While attempting to insert a custom header in an AngularJS request for the first time, I encountered the following error:
angular.js:10671Error: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'x-api-key:' is not a valid HTTP header field name.
Below is the code snippet located at the highest 'app' level:
var movieApp = angular.module('movieApp', ['ngAnimate']);
movieApp.config(['$httpProvider', function ($httpProvider) {
$httpProvider.defaults.headers.common = {
'x-api-key:' : 'key'
};
}])
I am unsure of what I might be doing incorrectly or misunderstanding. How can I successfully add this header to either all requests or just one?