1

我正在使用AngularFireFirebase和AngularJS之間的接口庫)。如何使用AngularFire調用Firebase JS方法

我想在我的角碼中調用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(); 
} 

回答

2

我想通了,我可以寫一個JavaScript函數外app.controller所要求的火力地堡方法和app.controller即內部稱之爲角方法裏面。

下面是我更新的代碼

// 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); 
    }); 
} 
相關問題