angular - Angular5 - 如何检查模块是否已加载
问题描述
在 Angular 5 中,我需要知道模块是否已经加载,以免显示微调器。目前我的代码是这样的:
constructor(private loaderService: LoaderService, private router: Router, @Inject(DOCUMENT) private document: Document) {
this.router.events.subscribe(event => {
console.log(this.router);
if (event instanceof NavigationStart) {
this.isSpinnerVisible = true;
} else if (event instanceof NavigationEnd || event instanceof NavigationCancel || event instanceof NavigationError) {
this.isSpinnerVisible = false;
}
}, () => {
this.isSpinnerVisible = false;
});
}
这样,如果模块已经被加载,我仍然显示模块十分之一秒。有什么想法?
解决方案
您可以使用全局变量(是的,不建议这样做,但它们的存在是有原因的,所以利用它)
export class MyAppModule {
constructor() {
if (!window['loaded_modules']) { window['loaded_modules'] = []; }
window['loaded_modules'].push(this.constructor.name);
}
}
推荐阅读
- simplex - 单纯形算法 - 最坏情况
- python-3.x - 如何使用 2 个列表并将值合并到一个字典中
- python-3.x - 如何从 OrangeML 模型中获取 Scikit-learn 模型输出?
- javascript - 如何使用猫鼬打开和关闭 TTL 索引?
- xamarin - 以 Xamarin 形式播放视频 - 无法播放视频
- django - 带有反应的Django csv输出
- java - 如何在 Retrofit 上上传没有标题和容器的文件
- android-studio - 更新插件后的警告
- sql - 选择具有特定值的列(虚拟表)
- c# - 从 HelixViewport3D 创建图像