如何在我的项目中正确安装 ngx-recaptcha? [英] how can I install correctly ngx-recaptcha on my project?
问题描述
我正在做一个表格来注册一个广告,但是当我安装了 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 ngx-captcha@5.0.4
[ReCaptcha V3]
降级时,方法execute
参数较少.this.reCaptchaV3Service.execute(this.siteKey, 'homepage', (token) => {console.log('这是你的令牌:', 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
上添加:
<代码><样式>.grecaptcha-badge { 可见性:崩溃!重要;}</style>
这篇关于如何在我的项目中正确安装 ngx-recaptcha?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!