angular - Using component from imported module inside of child modules -


i have module export component expose other modules, want use component in modules children of module, importing first module in parent module enable use inside of child modules but, not convinced best way it.

this shared module in root folder component want use:

app/shared/shared.module.ts

import {dtcomponent} './dt.component';  @ngmodule({   imports: [     commonmodule   ],   exports: [     dtcomponent   ],   declarations: [     dtcomponent   ] }) export class datepmodule{ } 

i have module in app folder import datepmodule this:

app/contacts/contacts.module.ts

import {datepmodule} '../shared/shared.module.ts';  @ngmodule({   imports: [     commonmodule,     datepmodule   ] }) export class ctmodule{ } 

i need use dtcomponent directly in components of ctmodule, need component in other component in child modules of ctmodule.

i can importing again datepmodule inside of child modules of ctmodule not convinced best approach.

app/contacts/other/other.module.ts

import {datepmodule} '../../shared/shared.module.ts';  @ngmodule({   imports: [     commonmodule,     datepmodule   ] }) export class othermodule{ } 

my question is, why need import again datepmodule if imported in parent module? if delete import in othermodule component dtcomponent not recognized part of module.

why need import again datepmodule if imported in parent module

there's no hierarchy between modules import 1 another. modules merged 1 module definition factory components. if use lazy-loading, still same applies. lazy-loaded module , shared module merged , there no hierarchy between them.

to learn more, read avoiding common confusions modules in angular. here quote:

the biggest confusion regarding imports in modules developers think makes hierarchy. , it’s reasonable assume module imports other modules becomes parent module imports. however, that’s not happens. modules merged during compilation phase. , non-lazy loaded modules not create hierarchy.

however, module imports/exports can enforce declarable types encapsulation during compilation. if want use declarable types module, have explicitly import module or other module re-exports required module. compiler controls encapsulation when parsing templates , explicit imports provide context know components can used children in template.

i can importing again datepmodule inside of child modules of ctmodule not convinced best approach.

that correct approach if want use declarable types datepmodule inside othermodule.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -