拦截器注入:
app.config(function($httpProvider) {
$httpProvider.interceptors.push('TokenInterceptor');
})
拦截器:
app.factory('TokenInterceptor', function($q,$location) {
return{
request:function(config) {
//console.log("拦截。。。。。");
//console.log(config);
config.headers['Content-Type'] = YourHeaderType;
config.headers.token = YourToken;
},
response:function(response) {
console.log(response)
return response || $q.when(response);
},
responseError:function(rejection) {
console.log(rejection)
return $q.reject(rejection);
}
};
})