【问题标题】:Cannot read property 'RecaptchaVerifier' of undefined in Angular无法读取 Angular 中未定义的属性“RecaptchaVerifier”
【发布时间】:2021-10-23 19:04:58
【问题描述】:

我正在尝试使用来自 firebase 的 signInWithPhoneNumber 发送消息,但在实施时出现以下错误,我还导入了 firebase 仍然是同样的问题。

import firebase from 'firebase/app';
import { environment } from 'src/environments/environment';

export class TabPage implements OnInit{
  code: string = '+91';
  spin: boolean = false;
  otpSent:boolean = false;


  recaptchaverifier;
  confirmationResult: firebase.auth.ConfirmationResult;
  phoneNumber: string;
ngOnInit(){
    this.recaptchaverifier = new firebase.auth.RecaptchaVerifier('recaptcha-container');
    this.sendOTP();
  }

sendOTP(){
    var phNo = this.code+'******';

    this.spin = true;
    firebase.auth().signInWithPhoneNumber(phNo,this.recaptchaverifier).then(result=>{
      this.phoneNumber = phNo;
      this.otpSent = true;
      this.confirmationResult = result;
      this.spin = false;
      console.log(result);
    }).catch(err=>{
      this.spin = false;
      alert(err);
    });
  }
}

【问题讨论】:

    标签: javascript angular firebase ionic-framework firebase-authentication


    【解决方案1】:

    您只是在导入核心 Firebase SDK。为了使用 Firebase 身份验证,您还需要通过添加以下内容来导入该 SDK:

    import 'firebase/auth';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-12
      • 2015-09-08
      • 2016-05-12
      • 2019-07-25
      相关资源
      最近更新 更多