【发布时间】:2020-07-02 10:46:21
【问题描述】:
我在我的 Angular 7 项目中使用Angular Google Recaptcha,安装后它就可以工作了。但问题是我看不到如何在他们提供的文档中获取 Recaptcha 令牌。有人知道吗?
到目前为止,我在文档中只看到了两个函数。这是完整的工作包吗?
【问题讨论】:
标签: angular typescript recaptcha
我在我的 Angular 7 项目中使用Angular Google Recaptcha,安装后它就可以工作了。但问题是我看不到如何在他们提供的文档中获取 Recaptcha 令牌。有人知道吗?
到目前为止,我在文档中只看到了两个函数。这是完整的工作包吗?
【问题讨论】:
标签: angular typescript recaptcha
根据文档,您可以将包与反应式表单和模板驱动表单一起使用。他们还在https://github.com/JamesHenry/angular-google-recaptcha#readme 中提供了两个示例。
如果您采用响应式表单方法,则可以从 FormControl 值中获取令牌,如下所示:
import { Component, On Init } from '@angular/core';
import { FormControl } from '@angular/forms';
@Component({
selector: 'app',
template: `
<recaptcha
[formControl]="myRecaptcha"
(scriptLoad)="onScriptLoad()"
(scriptError)="onScriptError()"
></recaptcha>
`
})
export class AppComponent implements onInit {
myRecaptcha = new FormControl(false);
ngOnInit() {
this.myRecaptcha.valueChanges.subscribe(token => console.log(token));
}
onScriptLoad() {
console.log('Google reCAPTCHA loaded and is ready for use!')
}
onScriptError() {
console.log('Something went long when loading the Google reCAPTCHA')
}
}
【讨论】: