Skip to content

Instantly share code, notes, and snippets.

@halfbaked
Created July 1, 2013 11:40
Show Gist options
  • Save halfbaked/5900137 to your computer and use it in GitHub Desktop.
Save halfbaked/5900137 to your computer and use it in GitHub Desktop.
ngular.module('http-loading-interceptor', ['spinner']).config([
'$httpProvider', 'spinnerProvider', function($httpProvider, spinnerProvider) {
var interceptor;
interceptor = function(data, headersGetter) {
spinnerProvider.startSpinner();
return data;
};
return $httpProvider.defaults.transformRequest.push(interceptor);
}
]).config([
'$httpProvider', 'spinnerProvider', function($httpProvider, spinnerProvider) {
var interceptor;
interceptor = [
'$q', '$window', function($q, $window) {
var error, success;
success = function(response) {
spinnerProvider.stopSpinner();
return response;
};
error = function(response) {
spinnerProvider.stopSpinner();
return $q.reject(response);
};
return function(promise) {
return promise.then(success, error);
};
}
];
return $httpProvider.responseInterceptors.push(interceptor);
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment