I am trying to implement an application wide, loading bar. So that when a user clicks any of the link in my application and while the data is being downloaded it should display a loading bar on top.
Something like this:
http://chieffancypants.github.io/angular-loading-bar/
Currently, what I have done is added a global singleton service with a Boolean property, isLoading. In my main app component template I have added angular material2 progress bar.
<md-progress-bar mode="indeterminate" *ngIf="_globalService.isLoading"></md-progress-bar>
Now, whenever I initiate an http request, I set isLoading property of that service to true in that component. And when that request completes I set it to false.
In my current case, I have to inject the service in my all of the components and manually set isLoading to true or false.
I was wondering is there any way to capture the initiation and completion of all ajax requests across my application, so that I just subscribe to that and don't have to handle it manually.