Created
March 28, 2013 19:35
-
-
Save zivester/5266158 to your computer and use it in GitHub Desktop.
httpInterceptor for broadcasting open events
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
| .factory('httpInterceptor', function($q, $injector, $rootScope){ | |
| var $http; | |
| function open(num){ | |
| $rootScope.$broadcast('httpOpen', num); | |
| } | |
| function close(num){ | |
| $rootScope.$broadcast('httpClose', num); | |
| } | |
| return function(promise){ | |
| $http || ($http = $injector.get('$http')); | |
| open($http.pendingRequests.length); | |
| return promise.then( | |
| function(response){ | |
| close($http.pendingRequests.length); | |
| return response; | |
| }, | |
| function(response){ | |
| close($http.pendingRequests.length); | |
| return $q.reject(response); | |
| } | |
| ); | |
| }; | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment