import { Injectable } from '@angular/core'; import { Subject } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class InProgressLoaderService { private loader = new Subject(); private counter = 0; showLoader() { return this.loader.asObservable(); } resetCounter() { this.counter = 0; } getCounter() { return this.counter; } startLoader() { this.counter++; this.loader.next(true); } stopLoader() { this.counter > 0 ? this.counter-- : ''; if (this.counter === 0) { this.loader.next(false); } } }