我以前看过有关此问题的帖子,但它们要么已经过时,要么提供与我的设置非常相似的解决方案。
基本上,我的 Controller 中有两个函数:authCtrl.login 和 authCtrl.register。寄存器对 Auth.$createUserWithEmailAndPassword() 的调用工作正常,但登录对 Auth.$authWithPassword() 的调用则不然,因为我收到“..不是函数”错误。我一生都无法弄清楚这里出了什么问题。
这是我的设置:
auth.service.js:
angular.module('angularfireSlackApp')
.factory('Auth', function($firebaseAuth, $firebaseObject){
var auth = $firebaseAuth();
return auth;
});
auth.controller.js:
angular.module('angularfireSlackApp')
.controller('AuthCtrl', function(Auth, $state){
var authCtrl = this;
authCtrl.user = {
email: '',
password: ''
};
authCtrl.login = function() {
// Why is this not a function
Auth.$authWithPassword(authCtrl.user)
.then(function (auth){
$state.go('home');
}, function (error){
authCtrl.error = error;
});
}
authCtrl.register = function() {
Auth.$createUserWithEmailAndPassword(authCtrl.user.email, authCtrl.user.password)
.then(function (user){
authCtrl.login();
}, function (error){
authCtrl.error = error;
});
}
});
最佳答案
尝试$signInWithEmailAndPassword
关于javascript - $authWithPassword 不是 AngularFire 2.x 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38670049/