Angular 2 - Lifecycle hooks for lazy loaded modules(Angular 2 - 延迟加载模块的生命周期钩子)
问题描述
我正在使用延迟加载的 Angular 模块开发应用程序.
I am in the process of developing an application using lazy loaded Angular modules.
我有一个简单的问题:
是否可以在加载模块时捕获事件?
Is it possible to catch an event when a module is loaded?
例如 OnInit.此链接解释了生命周期钩子,但它仅适用于组件:组件的生命周期钩子
For example OnInit. This link explains life cycle hooks but it is only for components: Lifecycle hooks for components
我找不到任何解释如何挂钩模块的文档.
I cant find any documentation that explains how to hook in for modules.
有人知道如何解决这个问题吗?
Does someone have an idea of how to solve this?
谢谢
推荐答案
延迟加载模块的构造函数应该这样做
The constructor of the lazy loaded module should do that
@NgModule({...})
export class MyLazyModule {
constructor(/* service injection here if required */) {
console.log('lazy module loaded');
}
}
这篇关于Angular 2 - 延迟加载模块的生命周期钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Angular 2 - 延迟加载模块的生命周期钩子


基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01