【发布时间】:2015-04-15 10:25:02
【问题描述】:
我正在尝试将我的 Firebase 身份验证逻辑从控制器转移到工厂,但遇到了基本设置问题。我正在使用 Angularfire 在我的应用中完成身份验证,并遵循文档here。
在我的控制器中一切正常,但我不确定如何在工厂中正确设置代码。我当前的代码如下:
angular
.module('app')
.factory('authService', authService);
authService.$inject = ['$firebaseAuth'];
var ref = new Firebase('https://[MY-FIREBASE].firebaseio.com');
var auth = $firebaseAuth(ref);
return {
createUser(email,password): auth.$createUser({
email: email,
password: password
}).then(function(userData) {
$location.path('/people');
}).catch(function(error) {
alert(error);
}),
connectFacebook: auth.$authWithOAuthPopup("facebook").then(function(authData) {
$location.path('/places');
}).catch(function(error) {
alert("Authentication failed:", error);
}),
removeUser: auth.$removeUser({
email: vm.email,
password: vm.password
}).then(function() {
alert('User removed');
}).catch(function(error) {
alert(error);
})
}
我的目标是将这个工厂注入我的登录控制器并连接调用适当函数的点击事件,例如authService.createUser($scope.email,$scope.password);。
【问题讨论】:
标签: javascript angularjs firebase factory angularfire