如何在我的项目中正确安装 ngx-recaptcha?

how can I install correctly ngx-recaptcha on my project?

我正在做一个表格来注册一个广告,但是当我安装 recaptcha 时它不起作用好吧,我无法重置它或重新加载它,等等,我已经严格按照教程进行操作什么都没有,这是页面,意思是 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]
    });

它抛出这个错误:

ERROR in ../node_modules/ngx-captcha/lib/components/base-recaptcha.component.d.ts(13,44):错误 TS1039:环境上下文中不允许使用初始化程序。 ../node_modules/ngx-captcha/lib/components/invisible-recaptcha.component.d.ts(13,31):错误 TS1039:环境上下文中不允许使用初始化程序。 ../node_modules/ngx-captcha/lib/components/recaptcha-2.component.d.ts(13,56):错误 TS1039:环境上下文中不允许使用初始化程序。

之后一切正常,只是在页面中显示正确的标签,但我无法对其执行任何操作,无法重置,无法验证... 有人可以帮助我。

我遇到了同样的错误,但使用的是 reCaptcha v3。

解决方案是将软件包降级到版本 5.0.4。

npm install ngx-captcha@5.0.4

[ReCaptcha V3]

降级时,方法execute的参数较少。 this.reCaptchaV3Service.execute(this.siteKey, 'homepage', (token) => { console.log('This is your token: ', token); });

[删除 ReCaptcha V3 徽章]

index.html 添加:

<style> .grecaptcha-badge { visibility: collapse !important; } </style>