Skip to content

Instantly share code, notes, and snippets.

@kkurni
Last active December 13, 2015 18:49
Show Gist options
  • Save kkurni/4958276 to your computer and use it in GitHub Desktop.
Save kkurni/4958276 to your computer and use it in GitHub Desktop.
AngularJS Loading interceptor example
KK.factory('httploadingInterceptor',['$q','$rootScope', function ($q, $rootScope) {
return function (promise) {
$rootScope.loading = true;
return promise.then(function (response) {
// hide the spinner
$rootScope.loading = false;
return response;
}, function (response) {
// hide the spinner
//$rootScope.loading = false;
return $q.reject(response);
});
};
}]);
/* Example how to use it
KK.config(['$routeProvider', '$httpProvider', function($routeProvider, $httpProvider) {
//set loading interceptor
$httpProvider.responseInterceptors.push('httpResponseInterceptor');
}]);
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment