//intercepts all inbound/outbound ajax data evoapp.factory('httpInterceptor', function ($rootScope, $q){ //http://endlessindirection.wordpress.com/2013/05/19/angularjs-global-loading-message-with-http-interceptors/ var activeRequests = 0; var started = function(broadcastEvents){ if(activeRequests == 0 && broadcastEvents === true) { $rootScope.$broadcast('loadingStatusActive'); } activeRequests++; }; var ended = function(response){ //intercept SECURITYEXCEPTION responses //if(!response.data.success && response.data.response) //{ // if(response.data.response.ServerResponse.length > 0) // { // var sr = response.data.response.ServerResponse[0]; // if(sr.MessageType == 'SECURITYEXCEPTION') // { // $rootScope.$broadcast('response', {response: response.data}); // } // } //} activeRequests--; if(activeRequests==0) { $rootScope.$broadcast('loadingStatusInactive'); } }; return { request: function (config){ started(config.$$broadcastEvents); return config || $q.when(config); }, // On request failure requestError: function (rejection){ ended(rejection); return $q.reject(rejection); }, // On response success response: function (response){ ended(response); return response || $q.when(response); }, // On response failure responseError: function (rejection){ ended(rejection); return $q.reject(rejection); } }; }); //instantiate httpInterceptor evoapp.config(function ($httpProvider){ $httpProvider.interceptors.push('httpInterceptor'); });