我正在尝试逐行找出问题所在,这里有什么需要更改吗?
Failed to instantiate module tickertags due to: Error: [$injector:strictdi] http://errors.angularjs.org/1.4.1/$injector/strictdi?p0=f...) at Error (native) at http://localhost/static/dashboard/libs/angular/angular.min.js:6:416 at Function.db.$$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');
});
}
}
});
})
最佳答案
是的,他们确实需要注入(inject)器来实现缩小。
.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);
}
};
}])
希望我没有写错,但你明白了。
关于javascript - 找不到我的 Angular minify bug 在哪里,配置或运行函数是否需要 [] 语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31250569/