繁体   English   中英

$ authWithPassword不是AngularFire 2.x中的函数

[英]$authWithPassword is not a function in AngularFire 2.x

我以前看过有关此问题的帖子,但它们要么过时,要么提供与我的设置非常相似的解决方案。

基本上,我的控制器中有两个功能: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;
});
}

});

也许可以基于Aaron Saunders使用angularjs和angularfire回答的内容获得更完整的答案:

var auth = $firebaseAuth();

$scope.loginUser = function (email, password) {
        auth.$signInWithEmailAndPassword(email, password).then(function(firebaseUser) {
            console.log("User Logged in successfully with uid: " + firebaseUser.uid);
        }).catch(function(error) {
            console.log("An Authentication error occurred: " + error);
        });
    };

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM