Hi, I am trying to modify HTTP headers from within a controller. Although I know it can be done in the config using $httpProvider, that's not the approach I want to take.
When I attempted this code snippet, I encountered an error saying "push of undefined."
$http.interceptors.push([function() {
return {
'request': function(config) {
config.headers = config.headers || {};
// Adding a nonce to prevent CSRF issues
config.headers['X-WP-Nonce'] = myLocalized.nonce;
return config;
}
};
}]);