Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未定义的角度拦截器_Javascript_Angularjs_Interceptor - Fatal编程技术网

Javascript 未定义的角度拦截器

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

我的angularjs应用程序导致错误:

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”注释导致错误,顺便说一句,我通过切换顺序修复了它。谢谢好的,很高兴能帮助你:)