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.
You can use angular interceptor to manage http request calls
https://stackoverflow.com/a/49632155/4976786
Here are the
currentpast AngularJS incantations:Here is the rest of it (HTML / CSS)....using
to toggle it. NOTE: the above is used in the angular module at beginning of post
If you are using ngResource, the $resolved attribute of an object is useful for loaders:
For a resource as follows:
You can link a loader to the $resolved attribute of the resource object:
This really depends on your specific use case, but a simple way would follow a pattern like this:
And then react to it in your template:
For page loads and modals the easiest way is to use the ng-show direcive and use one of the scope data variables. Something like ng-show="angular.isUndefined(scope.data.someobject)". As the data is undefined the spinner will show. Once the service returns with data and scope is populated, the spinner will be hidden.
The following way will take note of all requests, and hide only once all requests are done: