我在我的Angular 7项目中使用了Angular Google Recaptcha,在我安装它之后它就可以工作了。但问题是,我不知道如何在他们提供的文档中重新获得Recaptcha令牌。有人知道吗?
到目前为止,我在文档中只看到了两个函数。这是完整的工作包吗?
发布于 2020-07-02 10:46:21
根据文档,您可以将该包与反应式表单和模板驱动表单一起使用。他们还在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')
}
}https://stackoverflow.com/questions/62688025
复制相似问题