如何使用AngularFire调用Firebase JS方法

How to call Firebase JS method using AngularFire

本文关键字:JS 方法 Firebase 调用 何使用 AngularFire      更新时间:2023-09-26

我正在使用AngularFire(Firebase和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();
}

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

下面是我更新的代码

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

上面的JS函数是从下面的角度函数调用的

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