【问题标题】:How to call Firebase JS method using AngularFire如何使用 AngularFire 调用 Firebase JS 方法
【发布时间】:2016-07-30 02:53:05
【问题描述】:

我正在使用AngularFireFirebase 和 AngularJS 之间的接口库)。

我想在我的 Angular 代码中调用 javascript 方法 sendEmailVerification()。当我实现以下代码时,我收到一条错误消息:$scope.authObj.sendEmailVerification is not a function. 这可能是因为我试图在 AngularJS (AngularFire) 中使用 javascript 方法。

有没有办法通过使用 AngularFire 来使用 Javascript 方法?

$scope.signUp = function() {

  $scope.authObj.$createUserWithEmailAndPassword($scope.email, $scope.password)
    .then(function(firebaseUser) {

      $scope.sendVerifyEmail();

    }).catch(function(error) {
      console.error("Error: ", error);
    });
}

$scope.sendVerifyEmail = function(){
  $scope.authObj.sendEmailVerification();
}

【问题讨论】:

    标签: javascript angularjs firebase angularfire firebase-authentication


    【解决方案1】:

    我刚刚发现我可以使用所需的 Firebase 方法在 app.controller 外部编写一个 javascript 函数,并从 app.controller 内部(即 Angular 方法内部)调用它。

    下面是我更新的代码

    // The below JS function written outside app.controller
    function sendVerifyEmail(firebaseUser){
      firebaseUser.sendEmailVerification();
    }
    

    上面的JS函数是从下面的angular函数中调用的

    $scope.signUp = function() {
    
      $scope.authObj.$createUserWithEmailAndPassword($scope.email, $scope.password)
        .then(function(firebaseUser) {
    
          sendVerifyEmail(firebaseUser);
    
        }).catch(function(error) {
          console.error("Error: ", error);
        });
    }
    

    【讨论】:

      猜你喜欢
      • 2014-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-14
      • 1970-01-01
      • 1970-01-01
      • 2020-05-17
      相关资源
      最近更新 更多