Angular 2 - 延迟加载模块的生命周期钩子 [英] Angular 2 - Lifecycle hooks for lazy loaded modules

查看:21
本文介绍了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 - 延迟加载模块的生命周期钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆