我正在尝试让用户登录并在我的angularfire应用程序中从/ route继续。但是,当我在MainController中时,我得到了未知的提供程序错误。 这是我的工作;
var app = angular.module("myApp", ['firebase', 'ngRoute']);
这是firebaseAuth的工厂。
app.factory("Auth", ["$firebaseAuth",
function($firebaseAuth) {
return $firebaseAuth();
}
]);
这是来自authenticating with routers angularfire教程。
app.run(["$rootScope", "$location", function($rootScope, $location) {
$rootScope.$on("$routeChangeError", function(event, next, previous, error) {
if (error === "AUTH_REQUIRED") {
$location.path("/login");
}
});
}]);
app.config(["$routeProvider", function($routeProvider) {
$routeProvider.when("/login", {
controller: "LoginController",
templateUrl: "views/login.html",
resolve: {
"currentAuth": ["Auth", function(Auth) {
return Auth.$waitForSignIn();
}]
}
}).when("/", {
controller: "MainController",
templateUrl: "views/home.html",
resolve: {
"currentAuth": ["Auth", function(Auth) {
return Auth.$requireSignIn();
}]
}
});
}]);
在登录页面我可以通过谷歌弹出登录,我可以在浏览器中看到cookie。
app.controller("LoginController", ["$scope", "currentAuth", "Auth", function($scope, currentAuth, Auth) {
$scope.auth = Auth;
$scope.auth.$onAuthStateChanged(function(firebaseUser) {
$scope.firebaseUser = firebaseUser;
});
}]);
当我打开" /"路径,它失败并创建像this
这样的错误app.controller("MainController", [ "$scope", "$location", "$firebaseArray", "currentAuth", function($scope, $location, $firebaseArray, currentAuth) {
var ref = firebase.database().ref();
if (currentAuth == undefined || currentAuth == null) {
$location.path('/login');
}
}]);
我错过了什么错误吗?
谢谢。