Here is your reliable source! https://developers.google.com/recaptcha/docs/invisible
It seems that div <div id="recaptcha-container"></div> has not yet been added to your DOM, which is in your class constructor.
Also, Angular 2 does not want you to directly modify the DOM. You must change the DOM with ElementRef or ViewChild! Good luck
UPDATE: Here's how to add it to dom. Run the command
iElement.html('<div id="recaptcha-container"></div>');
in angular2.
This command adds this element to dom!
UPDATE # 2: Try adding the following:
First install recaptcha from npm by doing
npm install angular2-recaptcha
Add the following to your SystemJS configuration:
System.config({ map: { 'angular2-recaptcha': 'node_modules/angular2-recaptcha' }, packages: { app: { format: 'register', defaultExtension: 'js' }, 'angular2-recaptcha': {defaultExtension: 'js', main:'index'} } });
Then add this module:
... import { ReCaptchaModule } from 'angular2-recaptcha'; ... ... @NgModule({ imports: [...,ReCaptchaModule] }) ...
Then add this to your html:
<re-captcha site_key="<GOOGLE_RECAPTCHA_KEY>"></re-captcha>
Replace GOOGLE_RECAPTCHA_KEY with your Google reCaptcha public key
source share