1

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,

1
  • 1
    You need to import SharedModule in every module (and child module) of Module A. Commented Dec 22, 2022 at 7:59

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

are you sure its bad practice? tree shaking should remove unused components, and the modular architecture of Angular should ensure that each module is defined once, no matter how many times its imported.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.