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 try something like this as well:
Create directive :
Then you add something like this to mainCtrl
And HTML can looks like this:
Here is my solution which i feel is alot easer that the other posted here. Not sure how "pretty" it is though, but it solved all my issues
I have a css style called "loading"
The html for the loading div can be whatever but I used some FontAwesome icons and the spin method there:
On the elements that you want to hide you simply write this:
and in the function i just set this on load.
I am using SignalR so in the hubProxy.client.allLocks function (when its done going through the locks) I juts put
This also hides the {{someField}} when the page is loading since I am setting the loading class on load and AngularJS removes it afterwards.
This is a simple way to show a spinner that does not require a third-party library, intercepters, or jQuery.
In the controller, set and reset a flag.
In the HTML, use the flag:
The
vm.starting
is settrue
when the XHR starts and cleared when the XHR completes.This works well for me:
HTML:
Angular:
While the promise returned from $http is pending, ng-show will evaluate it to be "truthy". This is automatically updated once the promise is resolved... which is exactly what we want.
Since the functionality of position:fixed changed recently, I had difficulty showing the gif loader above all elements, so I had to use angular's inbuilt jQuery.
Html
Css
Controller
Hope this helps :)
This is the easiest way to add a spinner i guess:-
You can use ng-show with the div tag of any one of these beautiful spinners http://tobiasahlin.com/spinkit/ {{This is not my page}}
and then you can use this kind of logic