问题描述
我以前看过有关此问题的帖子,但它们要么已经过时,要么提供了与我的设置非常相似的解决方案.
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() 的调用没有,因为我收到..is not a function"错误.我一辈子都无法弄清楚这里出了什么问题.
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;
});
}
});
推荐答案
try $signInWithEmailAndPassword
这篇关于$authWithPassword 不是 AngularFire 2.x 中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!