如何使用 AngularFire 调用 Firebase JS 方法

How to call Firebase JS method using AngularFire

我正在使用 AngularFire (Interfacing library between 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.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);
    });
}