Eliya Cohen
Eliya Cohen

Reputation: 11468

Angular Style Guide 04-11 - Use shared pipe inside core component

So I read the Style Guide of Angular > Core Feature Module > Style Guide 04-11:

Do gather application-wide, single-use components in the CoreModule. Import it once (in the AppModule) when the app starts and never import it anywhere else. (e.g. NavComponent and SpinnerComponent).

Why? Real world apps can have several single-use components (e.g., spinners, message toasts, and modal dialogs) that appear only in the AppComponent template. They are not imported elsewhere so they're not shared in that sense. Yet they're too big and messy to leave loose in the root folder.

I can relate to that. Although, I've stumbled across a small issue that makes me wonder if this style guide is recommended.

I've got some pipes that exist inside my SharedModule that I need to use inside a CoreModule's singular component.

I thought about 2 alternatives:

Is there another recommended alternative?

Upvotes: 2

Views: 99

Answers (1)

Massimo Costa
Massimo Costa

Reputation: 1860

Style Guide is not something you MUST follow, is only a collection of suggestions that works in 99% of projects.

Regarding the first solution (importing SharedModule inside CoreModule) you have to consider that the code will be tree-shaked so only the used code will be compiled. On the other hand for very huge applications might makes sense also to split the SharedModule in smaller pieces (but I'd avoid it).

Upvotes: 3

Related Questions