app.run(function($rootScope, $location, $http, $state, Auth) {
if (Auth.isLoggedIn()) { <-- WORKS FINE
Auth.setUser(Auth.getUser());
}
$rootScope.$on('unauthenticated', function(response) {
// Redirect to login page
if (!Auth.IsLoggedIn()) { <-- Auth.IsLoggedIn is not a function
$state.go('login');
} else {
alert('no access to view this page');
}
});
$rootScope.$on('serverError', function(response) {
// $rootScope.serverError = "Server Error";
});
});
知道为什么我在第 8 行收到“Auth.IsLoggedIn 不是函数”,但在第 2 行却工作正常吗?
谢谢!
最佳答案
第二次调用方法时,在方法名称中使用大写的 I。
Auth.isLoggedIn()
比较:
Auth.IsLoggedIn()
关于javascript - angularjs .$on 内的服务未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35964482/