-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-http-loading-interceptor.js
More file actions
executable file
·48 lines (41 loc) · 1.36 KB
/
angular-http-loading-interceptor.js
File metadata and controls
executable file
·48 lines (41 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(function() {
'use strict';
angular.module('httpLoadingInterceptor', [])
.factory('httpLoadingInterceptorService', [ "$q", "$rootScope", function($q, $rootScope) {
return {
request : function(config) {
// Shows the loader
$rootScope.$broadcast("httpLoadingInterceptor:show");
return config || $q.when(config)
},
response : function(response) {
// Hides the loader
$rootScope.$broadcast("httpLoadingInterceptor:hide");
return response || $q.when(response);
},
responseError : function(response) {
// Hides the loader
$rootScope.$broadcast("httpLoadingInterceptor:hide");
return $q.reject(response);
}
};
} ]).config([ "$httpProvider", function($httpProvider) {
$httpProvider.interceptors.push('httpLoadingInterceptorService');
} ])
.directive("httpLoadingInterceptorSpinner", function() {
return {
restrict : 'A',
template : '<div class="rect1"></div><div class="rect2"></div><div class="rect3"></div><div class="rect4"></div><div class="rect5"></div>',
link : function($scope, element, attrs) {
$scope.$on("httpLoadingInterceptor:show", function() {
// console.log('show');
element.addClass('loading-visible');
});
$scope.$on("httpLoadingInterceptor:hide", function() {
// console.log('hide');
element.removeClass('loading-visible');
});
}
};
})
})();