I'm Angular2 newbie and I have some difficulties with im(ex)porting modules.
According to official styleguide CoreModule is:
CoreModule - import once when the app starts and never import anywhere else.
Does this mean that all those exported stuff from Core module will be only available in the Module where it is imported only? There is no way to make those stuff available in some child module? I created dummy project just to test this behavior:
Dummy component:
@Component({
selector: 'dummy-component',
template: '<h4>Dummy component</h4>',
})
export class DummyComponent {}
Core module:
import { DummyComponent } from './dummy.component';
@NgModule({
declarations : [DummyComponent],
exports : [DummyComponent]
})
export class CoreModule {}
App module(root module):
@NgModule({
declarations: [AppComponent,],
imports: [BrowserModule, CoreModule, HomeModule, RoutingModule],
exports : [CoreModule],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Home module declares home component:
@Component({
selector: 'home-component',
template:
`
<h2>Home component</h2>
<dummy-component></dummy-component>
`
})
export class HomeComponent {}
When I try to run this code I got this error:
'dummy-component' is not a known element
If you want stuff in other modules, then put it into a shared module (feature module). CoreModule is not the right place.
Yes you need to import a module to every module where you want to use components, directives, or pipes from that module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With