Can't find out where my Angular minify bug is, do config or run functions require [] syntax?
我正在逐行找出问题所在,这里有什么需要改变的吗?
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | .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 函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | .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'); }); } } }); }) |
是的,它们确实需要注入器来进行缩小。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | .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); } }; }]) |
希望我没有错字,但你明白了。