简体   繁体   English

嵌套模块延迟加载角度

[英]Nested modules lazy loading angular

In my project, I have below module hierarchy.在我的项目中,我有以下模块层次结构。

在此处输入图像描述

And I have shared module which will be shared between Module A and all its children.我有共享模块,它将在模块 A及其所有子项之间共享。

Q: Do I have to import shared module in every child module of Module A or importing it in Module A is enough?问:我必须在模块 A的每个子模块中导入共享模块,还是在模块 A中导入就足够了?

Thanks,谢谢,

You have to import it in each child module separately, if that module will use at least one item from the Shared module.如果该模块将至少使用Shared模块中的一项,则必须分别将其导入每个子模块。

That being said, you should consider not having Shared module at all, since it's a bad practice.话虽如此,您应该考虑根本不使用 Shared 模块,因为这是一种不好的做法。 Imagine you have 20 items in your Shared module, and some of you child modules will use only one item from it.假设您的 Shared 模块中有 20 个项目,而您的一些子模块将只使用其中的一个项目。 Well, you will have to import the whole Shared module (even you will use only one item from it), which will increase the final bundle for your child module and decrease the performance.那么,您将不得不导入整个 Shared 模块(即使您只使用其中的一项),这将增加子模块的最终包并降低性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM