angular5.x全局loading解决方法
发布时间:2020-12-17 07:02:44 所属栏目:安全 来源:网络整理
导读:import { Router,ActivatedRoute,NavigationEnd,NavigationStart } from ‘@angular/router‘; private allLoading: boolean = false; ? constructor( private router: Router, private activatedRoute: ActivatedRoute ) { setTimeout(() = { this.routerCh
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;
});
});
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |