AngularJS:加载问题
获取错误未捕获错误:[$injector:cdep]在Angularjs服务加载中 下面是service.js App.factory'myHttpInterceptor',['Service',functionService{ var myHttpInterceptor={ 请求:functionconfig{ 如果!Service.isAnonymus{ config.headers['X-CSRFToken']=Service.token; } 返回配置; } }; 返回myHttpInterceptor; }]; App.config['$httpProvider',函数$httpProvider{ $httpProvider.interceptors.push'myHttpInterceptor'; }];AngularJS:加载问题,angularjs,spring,Angularjs,Spring,获取错误未捕获错误:[$injector:cdep]在Angularjs服务加载中 下面是service.js App.factory'myHttpInterceptor',['Service',functionService{ var myHttpInterceptor={ 请求:functionconfig{ 如果!Service.isAnonymus{ config.headers['X-CSRFToken']=Service.token; } 返回配置; } }; 返回myHttpInt
****Solution**:**
App.factory('csrfResponseInterceptor', [function () {
return{
response: function(response){
console.log(response.headers('X-CSRF-TOKEN'));
return response;
}
}
}]);
App.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.xsrfHeaderName = 'X-CSRF-TOKEN';
$httpProvider.interceptors.push(function() {
return {
response: function(response) {
$httpProvider.defaults.headers.common['X-CSRF-TOKEN'] = response.headers('X-CSRF-TOKEN');
return response;
}
}
});
}]);