Ok i have tons of $http()
calls all around the app code,
i'm wondering is there any way / best practice to detect when all $http()
around the app have finished ( success/error donesn't matter what they return, just need to know if finished )?
So that i can show a loading gif until they are loading ?
thanks
It is possible if you execute all requests by
$q.all
Using
ng-if
, you can show and hide loadinggif
.In case, if you use different
$http
call, then have acount
orarray
in the$rootScope
and update them whenever$http
complete. Based on thecount
orarray.length
enable the loadinggif
.Using answer by @karaxuna, I implement my solution like below. Plunker
Do it like this:
Then use event bound to
$rootScope
anywhere (preferable to use in directive):