问题描述
我以前见过有关此问题的帖子,但它们要么过时,要么提供与我的设置非常相似的解决方案.
I've seen posts about this problem before, but they're either outdated or offer a solution very similar to my setup.
基本上,我的控制器中有两个功能:authCtrl.login和authCtrl.register.寄存器对Auth.$ createUserWithEmailAndPassword()的调用工作正常,但是对Auth.$ authWithPassword()的登录名调用却不起作用,因为我收到"..不是函数"错误.无法为我的生活弄清楚这里出了什么问题.
Basically, I have two functions in my controller: authCtrl.login and authCtrl.register. The register's call to Auth.$createUserWithEmailAndPassword() works fine, but the login's call to Auth.$authWithPassword() does not, as I'm getting a "..is not a function" error. Can't for the life of me figure out what is wrong here.
这是我的设置:
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
这篇关于$ authWithPassword不是AngularFire 2.x中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!