Search code examples
javascriptangulartypescriptlazy-loading

Nested modules lazy loading angular


In my project, I have below module hierarchy.

enter image description here

And I have shared module which will be shared between Module A and all its children.

Q: Do I have to import shared module in every child module of Module A or importing it in Module A is enough?

Thanks,


Solution

  • You have to import it in each child module separately, if that module will use at least one item from the Shared module.

    That being said, you should consider not having Shared module at all, since it's a bad practice. Imagine you have 20 items in your Shared module, and some of you child modules will use only one item from it. 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.