angular5.x全局loading解决方法

import { Router, ActivatedRoute, NavigationEnd, NavigationStart } from '@angular/router';
private allLoading: boolean = false;
 
constructor(
private router: Router,
private activatedRoute: ActivatedRoute
) {
setTimeout(() => {
this.routerChange();
});
}
public routerChange() {
this.router.events
.filter(event => event instanceof NavigationStart)
.map(() => this.activatedRoute)
.map((route: any) => {
while (route.firstChild) route = route.firstChild;
return route;
})
.subscribe((event) => {
this.allLoading = true;
this.router.events
.filter(event => event instanceof NavigationEnd)
.map(() => this.activatedRoute)
.map((route: any) => {
while (route.firstChild) route = route.firstChild;
return route;
})
.subscribe((event) => {
this.allLoading = false;
});
});
}

猜你喜欢

转载自www.cnblogs.com/aisiqi-love/p/10331603.html
今日推荐