我在用primeng验证码 https://www.primefaces.org/primeng/#/captcha对于 Angular 6,我有一个问题。
当我尝试直接加载具有验证码确认的页面时,出现此错误:
错误类型错误:window.grecaptcha.render 不是函数
在 Captcha.push../node_modules/primeng/components/captcha/captcha.js.Captcha.init (captcha.js:42)
在 Captcha.push../node_modules/primeng/components/captcha/captcha.js.Captcha.ngAfterViewInit (captcha.js:32)
我只在我的index.html中初始化了验证码:
<script src="https://www.google.com/recaptcha/api.js?render=explicit" async defer></script>
但如果我从另一个页面路由到此页面,它就会起作用。
有什么想法如何解决吗?
我得到了这个,所以我所做的就是附加window.grecaptcha
反对我的组件,然后*ngIf
验证码直到grecaptcha.render
是真的。核实。
// In your component
ngOnInit(){
this.recaptcha = (window as any).grecaptcha;
}
// And then in your template
<ng-container *ngIf="recaptcha.render">
<p-captcha ...></p-captcha>
</ng-container>
这样做,验证码组件将不会运行,直到脚本执行并且render
函数存在于grecaptcha
全球的。
干杯。祝发现这个问题的人好运。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)