I'm doing a form to register an Ad, but when I installed the recaptcha it doesn't works Ok, I couldn't reset it or reload it, etc, I've followed the tutorial to the letter and nothing, this is the page, meanly enter link description here
<ngx-recaptcha2 #captchaElem
[siteKey]="siteKey"
(reset)="handleReset()"
(expire)="handleExpire()"
(load)="handleLoad()"
(success)="handleSuccess($event)"
[useGlobalDomain]="false"
[size]="size"
[hl]="lang"
[theme]="theme"
[type]="type"
formControlName="recaptcha">
</ngx-recaptcha2>
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { HttpClientModule } from '@angular/common/http';
import { FormsModule,ReactiveFormsModule } from "@angular/forms";
import { NgxCaptchaModule } from 'ngx-captcha';
@NgModule({
declarations: [
CreateadsComponent
],
imports: [
NgxCaptchaModule,
......
this.aFormGroup = this.formBuilder.group({
recaptcha: ['', Validators.required]
});
it throws this error:
ERROR in ../node_modules/ngx-captcha/lib/components/base-recaptcha.component.d.ts(13,44): error TS1039: Initializers are not allowed in ambient contexts. ../node_modules/ngx-captcha/lib/components/invisible-recaptcha.component.d.ts(13,31): error TS1039: Initializers are not allowed in ambient contexts. ../node_modules/ngx-captcha/lib/components/recaptcha-2.component.d.ts(13,56): error TS1039: Initializers are not allowed in ambient contexts.
and nothing works fine later, just show correct tag in the page, but I can't do anything with it, no reset, no validate... Somebody can help me please.
I was having the same error, but using reCaptcha v3.
The solution was to downgrade the package to version 5.0.4.
npm install ngx-captcha@5.0.4
[ReCaptcha V3]
When downgrading, the method
execute
has fewer parameters.this.reCaptchaV3Service.execute(this.siteKey, 'homepage', (token) => { console.log('This is your token: ', token); });
[Removing ReCaptcha V3 Badge]
On
index.html
add:<style> .grecaptcha-badge { visibility: collapse !important; } </style>