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');
  }
}

相关文章