【发布时间】:2021-02-16 09:07:50
【问题描述】:
我正在尝试使用 angular 的 firebase 实现 recaptcha,但出现以下错误。
ERROR TypeError: Cannot read property 'RecaptchaVerifier' of undefined
在 .ts 文件中,我正在尝试以下操作:
import firebase from 'firebase/app';
recaptchaVerifier: firebase.auth.RecaptchaVerifier;
constructor(private windowService: WindowService) {}
ngOnInit() {
this.windowRef = this.windowService.windowRef;
}
ngAfterViewInit() {
this.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container', {
size: 'normal',
callback: (response) => {
...
}
});
this.windowRef.recaptchaVerifier = this.recaptchaVerifier;
this.windowRef.recaptchaVerifier.render();
}
窗口服务
@Injectable({
providedIn: 'root'
})
export class WindowService {
get windowRef() {
return window;
}
}
在模板中:
<div id="recaptcha-container"></div>
我做错了什么。 提前感谢您的任何回复!
【问题讨论】:
标签: angular firebase firebase-authentication recaptcha angularfire2