I have a structure similar to https://angular.io/docs/ts/latest/guide/style-guide.html#04-11
src
app
core
core.module.ts
spinner
spinner.component.ts|html|css|spec.ts
spinner.service.ts|spec.ts
product
product-list.component.ts
product.module.ts
app.component.ts|html|css|spec.ts
app.module.ts
app-routing.module.ts
main.ts
index.html
...
The module product-module
is LAZY loaded when the route is /product/list
. Now, in the product component template i'm trying to use the component spinner
from the core, but i got the following error:
Error: Template parse errors:'spinner' is not a known element:
I suppose that is because the CoreModule
is not imported in the ProductModule
but the CoreModule
is already imported in the AppModule
.
When import the CoreModule
in the ProductModule
then works fine.
My questions are:
- The core module should not be imported only one time, in the AppModule?
- How can exports components in the core module to allow the use in any place without need import every time?
Edit1:
Reading this (https://angular.io/docs/ts/latest/guide/ngmodule.html#!#add-the-contactmodule) I can see:
Modules don't inherit access to the components, directives, or pipes that are declared in other modules. What AppModule imports is irrelevant to ContactModule and vice versa. Before ContactComponent can bind with [(ngModel)], its ContactModule must import FormsModule.
Reading the above, I suppose that is required import my CoreBundle to use theirs components.
But in the other documentation say (https://angular.io/docs/ts/latest/guide/style-guide.html#04-12)
Only the root AppModule should import the CoreModule.
That is a bit contradictory, unless the spinner
can be used only in the AppComponent, in this case, why put the spinner in the coreModule
and not directly in the AppModule
.
I'm missing something...?