Last active
December 13, 2015 18:49
-
-
Save kkurni/4958276 to your computer and use it in GitHub Desktop.
AngularJS Loading interceptor example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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