[英]Angular interceptors of undefined
My angularjs app causing an error: 我的angularjs应用导致错误:
TypeError: Cannot read property 'interceptors' of undefined
Following is my setup 以下是我的设置
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');
}]);
My interceptor: 我的拦截器:
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);
}
};
})
My angular version is 1.4.4, I had no idea what cause these error. 我的角度版本是1.4.4,我不知道是什么原因导致这些错误。
; ;
you did a simple mistake :) 你犯了一个简单的错误:)
you missed to put ngNotify
as an annotation 您错过了将
ngNotify
用作注释
add the "ngNotify"
to the annotation after ...,'JS_REQUIRES',
and you will good to go. 在
...,'JS_REQUIRES',
之后...,'JS_REQUIRES',
将"ngNotify"
添加到注释中...,'JS_REQUIRES',
您将可以正常使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.