1. Add following code in app.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
app.factory('httpInterceptor', ['$q', '$rootScope', function ($q, $rootScope) { var loadingCount = 0; return { request: function (config) { if (++loadingCount === 1) $rootScope.$broadcast('loading:progress'); return config || $q.when(config); }, response: function (response) { if (--loadingCount === 0) $rootScope.$broadcast('loading:finish'); return response || $q.when(response); }, responseError: function (response) { if (--loadingCount === 0) $rootScope.$broadcast('loading:finish'); return $q.reject(response); } }; } ]).config(['$httpProvider', function ($httpProvider) { $httpProvider.interceptors.push('httpInterceptor'); }]); |
2. Add below code in admin/main controller
1 2 3 4 5 6 7 |
$rootScope.$on('loading:progress', function () { $scope.loader = true; }); $rootScope.$on('loading:finish', function () { $scope.loader = false; }); |
3. add below html on common/layout/master page
1 |
<div class="loader" ng-show="loader==true"> Loader </div> add div in layout page |