import { ChangeDetectorRef, Component } from '@angular/core'; import { ConfigsService, MessageService } from 'pz-unit'; import { NavigationCancel, NavigationEnd, NavigationError, NavigationStart, Router } from '@angular/router'; @Component({ selector: 'app-root', templateUrl: './app.component.html', }) export class AppComponent { public hide = true; public constructor(private readonly router: Router, private readonly messageService: MessageService, protected loadConfig: ConfigsService, private readonly changeDetectorRef: ChangeDetectorRef) { // Manually control loading this.messageService.loadingSubject .subscribe((v: boolean) => { this.hide = v; this.changeDetectorRef.detectChanges(); }); this.loadConfig.loadFinished.subscribe(res => { if (res) { this.changeDetectorRef.detectChanges(); } }); this.router.events.subscribe((event) => { // show loading if (event instanceof NavigationStart) { this.hide = false; } if (event instanceof NavigationEnd || event instanceof NavigationCancel || event instanceof NavigationError ) { this.messageService.routerSubject.emit(event); // hide loading // setTimeout(() => { this.hide = true; // }, 100000); } } ); } }