我正在尝试使用Angularjs进行简单的登录功能。我分离了控制器并提供了一项服务,通过Firebase服务器对用户进行身份验证。我应该提到的另一件事是,我使用他们的API称为Angular Fire。问题是我试图触发$ rootScope。$ on函数。下面的代码:
myApp.controller('StatusController', function($scope, $rootScope, $firebase, $firebaseAuth) {
console.log($rootScope);
$rootScope.$on('$firebaseAuth:authWithPassword', function(e, authUser){
console.log("printsomething");
$scope.userEmail = authUser.userEmail;
}); //$firebaseAuth:login
});//StatusController
这里是认证服务:
myApp.factory('Authentication', function ($firebase, $firebaseAuth, FIREBASE_URL, $location) {
var ref = new Firebase(FIREBASE_URL);
console.log(FIREBASE_URL);
var simpleLogin = $firebaseAuth(ref);
var myObject = {
login: function (user) {
return **simpleLogin.$authWithPassword**({
email: user.email,
password: user.password
});
} //login
} //myObject
return myObject;
})
这里是哪里的认证将被调用。在我登记控制器:
myApp.controller('RegistrationController', function($scope, $firebaseAuth, $location, Authentication) {
$scope.login = function() {
Authentication.login($scope.user)
.then(function(user) {
$location.path('/meetings');
}, function(error) {
$scope.message = error.toString();
});
}//login
$scope.register = function() {
$location.path('/register');
}//register
});//
我甚至记录根范围内,看看我有()函数$内正确参数:
$$listeners: Object$firebaseAuth:authWithPassword: Array[1]0: function (e, authUser){length: 1
__proto__: Array[0]
请如果有人能帮助我将不胜感激。
在使用你的身份验证服务?您是否在代码中的任何其他位置使用Firebase进行身份验证? – GregL 2014-11-21 00:07:08
我在AngularFire的代码中看不到广播'$ firebaseAuth:authWithPassword'事件的地方。这是你在代码中播出的事件吗? – GregL 2014-11-21 00:54:08
如果你看看认证服务,它应该在那里。 $ firebaseAuth是一个参考,所以它应该有东西 – gmetrix 2014-11-21 01:02:50