Having some trouble with minification and AngularJS ;-(
I found this jsfiddle \"loading\" extender for HTTP request, through the AngularJS Wiki page.
It work
Just for others in the same situation... I followed @Stewie 's advice, and made this instead, which only uses AngularJS code, no stupid jQuery dependency ;-)
Service:
app.config([
"$httpProvider", function($httpProvider) {
var spinnerFunction;
$httpProvider.responseInterceptors.push("myHttpInterceptor");
spinnerFunction = function(data, headersGetter) {
return data;
};
return $httpProvider.defaults.transformRequest.push(spinnerFunction);
}
]).factory("myHttpInterceptor", [
"$q", "$window", "$rootScope", function($q, $window, $rootScope) {
return function(promise) {
$rootScope.$broadcast("loader_show");
return promise.then((function(response) {
$rootScope.$broadcast("loader_hide");
return response;
}), function(response) {
$rootScope.$broadcast("loader_hide");
$rootScope.network_error = true;
return $q.reject(response);
});
};
}
]);
Directive
app.directive("spinner", function() {
return function($scope, element, attrs) {
$scope.$on("loader_show", function() {
return element.removeClass("hide");
});
return $scope.$on("loader_hide", function() {
return element.addClass("hide");
});
};
});