我正在使用 AngularFire (Firebase 和 AngularJS 之间的接口(interface)库)。
我想调用 javascript 方法 sendEmailVerification()在我的 Angular 代码中。当我实现下面的代码时,我收到一条错误消息:$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);
});
}
关于javascript - 如何使用 AngularFire 调用 Firebase JS 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38669930/