I am using the $http
service of angular to make an ajax request.
How to show a loader gif during the ajax request?
I don't see any ajaxstartevent
or similar event in documentation.
I am using the $http
service of angular to make an ajax request.
How to show a loader gif during the ajax request?
I don't see any ajaxstartevent
or similar event in documentation.
Another solution to show loading between different url changes is:
And then in the markup just toggle the spinner with
ng-show="loading"
.If you want to display it on ajax requests just add
$scope.loading++
when the request starts and when it ends add$scope.loading--
.Sharing my version of the great answer from @bulltorious, updated for newer angular builds (I used version 1.5.8 with this code), and also incorporated @JMaylin's idea of using a counter so as to be robust to multiple simultaneous requests, and the option to skip showing the animation for requests taking less than some minimum number of milliseconds:
create directive with this code:
if you want to show loader for every http request call then you can use angular interceptor to manage http request calls ,
here is a sample code
https://github.com/wongatech/angular-http-loader is a good project for this.
Example here http://wongatech.github.io/angular-http-loader/
The code below shows a template example/loader.tpl.html when a request is happening.