Reputation: 1676
Hi I need to change http headers from inside a controller. It works in config by using $httpProvider but thats not what I am looking for.
I tried this but it says push of undefined.
$http.interceptors.push([function() {
return {
'request': function(config) {
config.headers = config.headers || {};
//add nonce to avoid CSRF issues
config.headers['X-WP-Nonce'] = myLocalized.nonce;
return config;
}
};
}]);
Upvotes: 2
Views: 121
Reputation: 1542
In the config object of $http you have a field headers which is a map of strings or functions.
You can use it like that :
$http.get('/someUrl', {
headers: { Authorization : 'Basic ' + encoded}
});
Upvotes: 4