本文介绍了如何在我的项目中正确安装ngx-recaptcha?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个注册广告的表格,但是当我安装Recaptcha时,它不能正常工作,我无法重置或重新加载它,依此类推,我已经按照教程中的内容进行了操作,但没有任何操作,这是该页面,即在此处输入链接描述

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]
    });

它抛出此错误:

../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:在环境中不允许使用初始化程序.

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.

推荐答案

我遇到了相同的错误,但是使用的是reCaptcha v3.

I was having the same error, but using reCaptcha v3.

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

The solution was to downgrade the package to version 5.0.4.

npm install [email protected]

[ReCaptcha V3]

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

When downgrading, the method execute has fewer parameters.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>

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

这篇关于如何在我的项目中正确安装ngx-recaptcha?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 11:49