app.module('appName').factory('tokenInterceptor', ['$q', function($q) {
return {
request: function(config) {
config.headers = config.headers || {};
config.headers['X-Access-Token'] = 'xYRTT342aa@@55#$@';
config.headers['X-User-Key'] = '
[email protected]'
config.headers['Content-Type'] = "application/json";
return config || $q.when(config);
},
response: function(res) {
return response || $q.when(res);
}
};
}]);
app.module('appName').config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push('tokenInterceptor');
}]);
Angular will call interceptors when a request is done to the server.