This library will help you indicate (track) the progress of you requests. When they are preparing, executing or if there is an error.
Its purpose is to be attached to any observable by providing IndicatorBehavioralSubject to it.
Add it to you project by executing the following:
npm i ngx-ready-set-go --save
TS
indicator: IndicatorBehaviorSubject = new IndicatorBehaviorSubject();
this.readySetGoService.getUsersFromAPI()
.pipe(indicate(this.indicator))
.subscribe((res: any) => {
console.log(res);
});
HTML
<div *ngIf="indicator | async as status">
<span>Loading: {{status.loading}}</span>
<span>Error: {{status.error}}</span>
<span>Loaded: {{status.loaded}}</span>
</div>
It has 3 states for now:
error: false, loaded: false, loading: false
They are all false on init.
- On prepare:
loading becomes true, all others false
- On catchError:
error becomes true, all others false
- On finalize:
loaded becomes true, all others false
I would be happy to get your feedback and suggestions