在我的 Web 应用程序中,我想验证用户是否有权继续。
这是我的 index.js 文件中的 .run 方法:
.run(function (event, toState, toParams, fromState, $window) {
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, $window) {
if (Auth.isLoggedIn && $window.localStorage.identityToken) {
var requiredAdmin = toState.data.requiredAdmin;
if (requiredAdmin && $window.localStorage.isAdmin){
$state.go(toState.name);
} else {
$state.go(fromState.name);
}
var shouldGoToMain = fromState.name === 'login' && toState.name !== 'app.dashboard' ;
if (shouldGoToMain){
$state.go('app.dashboard');
event.preventDefault();
} else {
$state.go(toState.name);
}
return;
} else {
$state.go('login');
return;
}
// unmanaged
});
});
控制台错误是:Uncaught Error: [$injector:strictdi] function(event, toState, toParams, fromState, $window) is not using explicit annotation and cannot be invoked in strict mode