Skip to content

Instantly share code, notes, and snippets.

@fisshy
Created September 14, 2014 11:47
Show Gist options
  • Save fisshy/7b5db0bc7bb74719486d to your computer and use it in GitHub Desktop.
Save fisshy/7b5db0bc7bb74719486d to your computer and use it in GitHub Desktop.
Http Interceptor for Angular JS
angular.module('model').factory('httpMiddletier',
function ($q, $rootScope) {
return {
request: function (config) {
$rootScope.loading = true;
return config || $q.when(config);
},
requestError: function (rejection) {
$rootScope.loading = false;
return $q.reject(rejection);
},
response: function (response) {
$rootScope.loading = false;
return response || $q.when(response);
},
responseError: function (rejection) {
$rootScope.loading = false;
return $q.reject(rejection);
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment