To implement default headers in Angular 1.0.x, you can use the following code:
$http.defaults.headers.common['Authentication'] = 'authentication';
For Angular 1.1.x+, you can utilize a request interceptor with this code:
myapp.factory('httpRequestInterceptor', function () {
return {
request: function (config) {
// To replace existing headers
config.headers = {'Authentication':'authentication'}
// To add without replacing existing headers
// config.headers['Authorization'] = 'authentication';
return config;
}
};
});
myapp.config(function ($httpProvider) {
$httpProvider.interceptors.push('httpRequestInterceptor');
});
Keep in mind that factories/services act as singletons, so make sure you don't need to change the 'authentication' value dynamically after instantiation.