angular - “AngularFireAuth”类型上不存在属性“RecaptchaVerifier”
问题描述
我正在使用 firebase、ionic + angularjs 实现电话身份验证代码,但在 RecaptchaVerifier 我的 TS 文件中出现错误
constructor(
private afauth: AngularFireAuth,
private windowService: WindowService,
private auth: AngularFireModule; ) { }
ngOnInit() {
this.windowRef = this.windowService.windowRef;
{
this.windowRef.recaptchaVerifier = new this.afauth.RecaptchaVerifier('recaptcha-container', {
size: 'invisible',
callback: () => {
this.disableOTPsendbutton = true;
}
});
this.windowRef.recaptchaVerifier.render();
}
}
sendOTP() {
this.afauth.signInWithPhoneNumber(this.phoneNumber, this.windowRef.recaptchaVerifier)
.then((confirmationResult) =>
{
this.windowRef.confirmationResult = confirmationResult;
}).catch(err => console.log('err1', err));
}
我遇到错误:
this.windowRef.recaptchaVerifier = new this.afauth.RecaptchaVerifier('recaptcha-container', {
vs代码中显示的错误是:
“AngularFireAuth”类型上不存在属性“RecaptchaVerifier”。
解决方案
您需要为 recaptcha 容器创建一个 div,如下所示
<div class='ion-center'
style="position:relative;z-index:10;width:100%;margin-top:2em;margin-left:2em;margin-right:auto;">
<div id="recaptcha-container"></div>
</div>
尝试从 npm 安装 firebase 包
npm install firebase --save
然后将其导入您的 page.ts 文件中,例如
import * as firebase from 'firebase';
用 firebase.auth 替换你的 afauth
this.windowRef.recaptchaVerifier=await new firebase.auth.RecaptchaVerifier('recaptcha-container',{'size':'invisible'});
你的 ngOnInit 应该像
ngOnInit {
this.windowRef=await this.windowService.windowRef;
this.windowRef.recaptchaVerifier=await new firebase.auth.RecaptchaVerifier('recaptcha-container',{'size':'invisible'});
}
推荐阅读
- javascript - webpack 包不让 html 识别我的 js 函数
- cassandra - 在未提供聚类列的情况下,每个分区由一行组成
- c# - 提取部分 JSON 内容(属性)并转换为 c# 对象?
- node.js - Node js路由顺序搞砸了
- wordpress - Wordpress Elementor 标题问题
- python - Python有序链表与引用正确名称的混淆
- android-studio - 在 VScode 和 Android Studio 中使用 Gradle 进行颤振时出错
- python - 一个函数中的一个函数会比单独定义两个函数占用更多的 RAM 内存吗?
- python - 如何使用 keras 根据之前的 epoch 精度更改学习率我正在使用 SGD 优化器?
- javascript - 如何从后面的代码在页面上显示带有验证器的引导模式