Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invisible reCAPTCHA integration with angular component

I want to integrate invisible recaptcha in angular 2 component.

Here is my code in login.component.html

 <button type="submit" class="g-recaptcha" data-sitekey="<Site-Key>" data-callback='onsubmit'> Log On </button>

And the login.component.ts has onsubmit method as below:

     onsubmit() {
  console.log("In onsubmit method");
}

I am getting the following error when i call onsubmit method from my login.component.ts

ReCAPTCHA couldn't find user-provided function:onsubmit

and how to get the 'g-recaptcha-response' in my login.component.ts.

like image 797
user1188867 Avatar asked Mar 01 '26 05:03

user1188867


1 Answers

reCaptcha Callback can not find your onsubmit function because its a Method in your component.

you can attach your global function to the window object like this :

window['onsubmit'] = () => {
    ...
}

you can do this in the constructor of your Component

like image 155
MajiD Avatar answered Mar 02 '26 21:03

MajiD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!