javascript - 在 Angular 2.0.0 中如何在解析数据时显示等待指示器?
我有一个基于 Angular 2.0.0 的项目,我想在导航路由时显示等待提示(GIF 或文本),并且必须像这样解析数据:
{
path: 'profile',
loadChildren: () => System.import('../profile/profile.module'),
resolve: {
profile: ProfileResolver
},
},
此外,预加载器需要应用到项目中的每个路由。谢谢。
答案#1
我会说你可以创建一个服务来监视路由事件,并根据 NavigationStart 和 NavigationEnd 事件,根据 isLoading 标志的值结合 [hidden] 来 显示/隐藏 加载。
代码
isLoading: bool = false;
constructor(router:Router) {
router.events.subscribe(event:Event => {
if(event instanceof NavigationStart) {
this.isLoading = true;
}
if(event instanceof NavigationCancel || event instanceof NavigationError) {
this.isLoading = false;
}
}
}
