Javascript 未定义的角度拦截器
我的angularjs应用程序导致错误:Javascript 未定义的角度拦截器,javascript,angularjs,interceptor,Javascript,Angularjs,Interceptor,我的angularjs应用程序导致错误: TypeError: Cannot read property 'interceptors' of undefined 以下是我的设置 var myApp = angular.module("MyApp",['ngResource','ngRoute','ui.router','ngMessages','ngResource','cfp.loadingBar','duScroll','ngAnimate','satellizer','pasca
TypeError: Cannot read property 'interceptors' of undefined
以下是我的设置
var myApp = angular.module("MyApp",['ngResource','ngRoute','ui.router','ngMessages','ngResource','cfp.loadingBar','duScroll','ngAnimate','satellizer','pascalprecht.translate','ngCookies','oc.lazyLoad','ui.bootstrap','toastr','ngNotify','door3.css','ngPassword'])
.config(['$stateProvider', '$urlRouterProvider','$controllerProvider', '$compileProvider', '$filterProvider', '$provide','$authProvider','$ocLazyLoadProvider','JS_REQUIRES','$httpProvider',function($stateProvider, $urlRouterProvider,$controllerProvider, $compileProvider, $filterProvider, $provide,$authProvider,$ocLazyLoadProvider,jsRequires,ngNotify,$httpProvider){
$httpProvider.interceptors.push('authInterceptor');
}]);
我的拦截器:
angular.module('MyApp')
.factory('authInterceptor', function($rootScope,$q,$window) {
return {
request: function(config){
config.headers = config.headers || {};
if($window.localStorage.getItem('token')){
config.headers.Authorization = 'Bearer ' + $window.localStorage.getItem('token');
}
return config;
},
response: function(response){
if(response.status === 401) {
// user not auth
}
return response || $q.when(response);
}
};
})
我的角度版本是1.4.4,我不知道是什么导致了这些错误
) 你犯了一个简单的错误:)
您没有将ngNotify
作为注释
在
、'JS_REQUIRES'、
之后添加“ngNotify”
到注释,您就可以开始了。添加“ngNotify”注释导致错误,顺便说一句,我通过切换顺序修复了它。谢谢好的,很高兴能帮助你:)