reCAPTCHA v3无法正常工作的角度6

编程入门 行业动态 更新时间:2024-10-24 21:26:48
本文介绍了reCAPTCHA v3无法正常工作的角度6-执行错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Angular 6实现Google reCAPTCHA v3.

I am implementing Google reCAPTCHA v3 with Angular 6.

<script src='www.google/recaptcha/api.js?render=KEY'></script>

在index.html

在我的AppComponent中,

In my AppComponent,

constructor( @Inject(DOCUMENT) private document: any ) { this.grecaptcha = this.document.grecaptcha; }

当我单击表单提交时,

this.grecaptcha.execute('KEY', { action: 'action_name' }) .then(function (token) { // Verify the token on the server. console.log(token); });

但是

ERROR TypeError:无法读取未定义的属性"execute"

ERROR TypeError: Cannot read property 'execute' of undefined

推荐答案

该对象应该在window中可用,因此您所需要做的就是在ts文件顶部声明它:

the object should be available from window, so all you need is to declare it on top of your ts file:

declare const grecaptcha: any;

然后您可以在班级中使用它,例如:

then you can use it in your class like:

grecaptcha.execute('KEY', { action: 'action_name' }) .then(function (token) { // Verify the token on the server. console.log(token); })

您也可以尝试安装键入@types/grecaptcha,以获得一些类型提示,使您的生活更轻松

You can also try to install the typings @types/grecaptcha, to get some type hinting to make your life a bit easier

更多推荐

reCAPTCHA v3无法正常工作的角度6

本文发布于:2023-11-03 12:30:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555141.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   角度   工作   reCAPTCHA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!