Angular 4+ Loading Service
- emits an event when the first http request is started
- emits an event when all http requests have finished
- push your own observables to the service to have them additionally tracked too
import { AngularLoadingModule } from 'angular-loading-service';
imports: [
...,
AngularLoadingModule
],
...
import { Component, OnInit } from '@angular/core';
import { LoadingService } from 'angular-loading-service';
@Component({
selector: 'example-component',
templateUrl: './example.component.html',
styleUrls: ['./example.component.scss']
})
export class ExampleComponent implements OnInit {
isLoading: boolean;
constructor(private loadingService: LoadingService) { }
ngOnInit() {
this.loadingService.loadingStart.subscribe(() => this.isLoading = true);
this.loadingService.loadingEnd.subscribe(() => this.isLoading = false);
}
}
this.loadingService.start(yourObservable);
const isLoading = this.loadingService.isLoading;