I'm quite new with angular 4 so what I need is to show a
spinner
<component-one></component-one>
<component-two></component-two>
<component-three></component-three>
<component-n></component-n>
<loading></loading>
<loading>
UPD: plunker. Take a look at app.ts
. Sorry for having everything in a single file.
In Angular 4.3 there is a new HttpClientModule which supports interceptors. The main idea is to have something like this:
@Injectable()
export class LoadingIndicatorService {
private _loading: boolean = false;
get loading(): boolean {
return this._loading;
}
onRequestStarted(): void {
this._loading = true;
}
onRequestFinished(): void {
this._loading = false;
}
}
And then you just apply the logic from Christopher's answer to your HttpInterceptor.
The only thing you should be aware of are simultaneous request. This can be solved for example by generating a unique identifier to each request and storing it somewhere until the request is finished.
Then you can have a global LoadingIndicator
component which injects LoadingIndicatorService
.
For more details on HttpClientModule: https://medium.com/codingthesmartway-com-blog/angular-4-3-httpclient-accessing-rest-web-services-with-angular-2305b8fd654b