【发布时间】:2015-09-07 23:18:41
【问题描述】:
var module = angular.module('timestamp-marker-example', []);
module.factory('timestampMarker',[function() {
var timestampMarker = {
request: function(config) {
console.log(config);
console.log(config.method);
console.log(config.url);
/* console.log(config.headers);*/
var head={
headers:{
'X-testing':'testing'
},
method:"POST"
}
config.push(head);
return config ;
},
response: function(response) {
return response;
}
};
return timestampMarker;
}]);
module.config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push('timestampMarker');
}]);
module.controller('ExampleController', ['$scope', '$http', function($scope, $http) {
$http.get('https://api.github.com/users/naorye/repos').then(function(response) {
console.log(response);
});
}]);
我想为拦截器的请求添加新的标头。如何添加它?我已经尝试过上面的代码。谁能帮我解决这个问题?
【问题讨论】:
标签: angularjs