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 - 延迟加载模块的生命周期钩子
基础教程推荐
- 检查 HTML5 拖放文件类型 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
