2

I have been reading this tutorial on creating a feature module : https://johnpapa.net/introducing-angular-modules-feature-modules-2/.

In this tutorial FormsModule is imported by shared.module.ts and then exported. Why is that ?

Also why does shared.module.ts also exports CommonModule. Why is that?

Also does this mean that I have to export all my SharedModule's imports ?

Best regards

1
  • Well, the shared module is a module to be shared among all modules if needed. Therefore, it can be used on other modules without you having to especify it on module declaration. Commented Nov 14, 2016 at 18:40

1 Answer 1

1

So that the importing module doesn't need to import them as well. I assume that using that module usually requires using CommonModule and FormsModule anyway and this way just adding ShardModule to imports: [] will do.

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

6 Comments

Why would I have to export them then ? When importing "SharedModule" shouldn't the DI thingy know that it depends on the FormsModule and make it available to the SharedModule ? What does any module importing the SharedModule care about the FormsModule which is an internal dependency of the SharedModule ?
If it's only an internal dependency, then you shouldn't export it. Exporting it is only for convenience of the user when it is expected that SharedModule is always used toghether with CommonModule and FormsModule so that the user only needs 1 import instead of 3.
But why would the user need to import CommonModule and FormsModule when importing SharedModule ? They are SharedModule's dependencies ? Shouldn't the DI automatically import them without me having to explicitly "export" them ? Does this mean also that I have to export all my SharedModule's "imports"
There is no "need". I said "for convenience".
So importing SharedModule will work even if I delete SharedModule's export statement ?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.