【问题标题】:Angular Google Recaptcha | How to get recaptcha token resultAngular Google Recaptcha |如何获取 recaptcha 令牌结果
【发布时间】:2020-07-02 10:46:21
【问题描述】:

我在我的 Angular 7 项目中使用Angular Google Recaptcha,安装后它就可以工作了。但问题是我看不到如何在他们提供的文档中获取 Recaptcha 令牌。有人知道吗?

到目前为止,我在文档中只看到了两个函数。这是完整的工作包吗?

【问题讨论】:

    标签: angular typescript recaptcha


    【解决方案1】:

    根据文档,您可以将包与反应式表单和模板驱动表单一起使用。他们还在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')
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-10-21
      • 2021-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      • 2015-10-07
      相关资源
      最近更新 更多