[英]Can't find out where my Angular minify bug is, do config or run functions require [] syntax?
我試圖逐行找出問題所在,這里是否需要更改?
無法實例化模塊標簽,原因如下:錯誤:[$ injector:strictdi] http://errors.angularjs.org/1.4.1/ $ injector / strictdi?p0 = f ...),位於http: //在Function.db上的//localhost/static/dashboard/libs/angular/angular.min.js:6:416.$$annotate
.constant('AUTH_EVENTS', {
loginSuccess : 'auth-login-success',
loginFailed : 'auth-login-failed',
logoutSuccess : 'auth-logout-success',
sessionTimeout : 'auth-session-timeout',
notAuthenticated : 'auth-not-authenticated',
notAuthorized : 'auth-not-authorized'
})
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/login');
$stateProvider
.state('dashboard', {
url: '/dashboard',
templateUrl: 'dashboard.html'
})
.state('login', {
url: '/login',
templateUrl: 'login/login.html',
controller: 'LoginCtrl',
data: {
authorizedRoles: ['All']
}
});
})
.config(function ($httpProvider) {
$httpProvider.interceptors.push([
'$injector',
function ($injector) {
return $injector.get('AuthInterceptor');
}]);
})
.factory('AuthInterceptor', function ($rootScope, $q, AUTH_EVENTS, $location) {
return {
responseError: function (response) {
$rootScope.$broadcast({
401: AUTH_EVENTS.notAuthenticated,
403: AUTH_EVENTS.notAuthorized,
419: AUTH_EVENTS.sessionTimeout,
440: AUTH_EVENTS.sessionTimeout
}[response.status], response);
if (response.status == 401) {
$location.path('/login');
}
return $q.reject(response);
}
};
})
我的.run函數
.run(function ($rootScope, AUTH_EVENTS, AuthService, $location) {
$rootScope.$on('$routeChangeStart', function (event, next) {
var authorizedRoles = next.data.authorizedRoles;
if (!AuthService.isAuthorized(authorizedRoles)) {
event.preventDefault();
// user is not allowed
if (AuthService.isAuthenticated()) {
$rootScope.$broadcast(AUTH_EVENTS.notAuthorized);
$location.path('/login');
// user is not logged in
}
else {
$rootScope.ifLoggedOut = true;
AuthService.check_login().then(function (user) {
$rootScope.ifLoggedOut = false;
if (user.role === 'Curator') {
$rootScope.isCurator = true;
}
$rootScope.currentUser = user;
$rootScope.username = user.username;
}, function() {
$rootScope.$broadcast(AUTH_EVENTS.notAuthenticated);
$location.path('/login');
});
}
}
});
})
是的,他們確實需要噴油器以實現最小化。
.config(['$stateProvider', '$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/login');
$stateProvider
.state('dashboard', {
url: '/dashboard',
templateUrl: 'dashboard.html'
})
.state('login', {
url: '/login',
templateUrl: 'login/login.html',
controller: 'LoginCtrl',
data: {
authorizedRoles: ['All']
}
});
}])
.config(['$httpProvider',
function ($httpProvider) {
$httpProvider.interceptors.push([
'$injector',
function ($injector) {
return $injector.get('AuthInterceptor');
}]);
}])
.factory('AuthInterceptor', ['$rootScope', '$q', 'AUTH_EVENTS', '$location',
function ($rootScope, $q, AUTH_EVENTS, $location) {
return {
responseError: function (response) {
$rootScope.$broadcast({
401: AUTH_EVENTS.notAuthenticated,
403: AUTH_EVENTS.notAuthorized,
419: AUTH_EVENTS.sessionTimeout,
440: AUTH_EVENTS.sessionTimeout
}[response.status], response);
if (response.status == 401) {
$location.path('/login');
}
return $q.reject(response);
}
};
}])
希望我沒有錯別字,但您明白了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.