I have a module that export a component to expose it to other modules, I want to use this component in modules that are children of another module, I am importing the first module in the parent module to enable use inside of child modules but, I am not completely convinced that is the best way to do it.
This is my shared module in root folder with the component that I want to use:
app/shared/shared.module.ts
import {dtComponent} from './dt.component';
@NgModule({
imports: [
CommonModule
],
exports: [
dtComponent
],
declarations: [
dtComponent
]
})
export class DatePModule{ }
I have another module in app folder that import DatePModule like this:
app/contacts/contacts.module.ts
import {DatePModule} from '../shared/shared.module.ts';
@NgModule({
imports: [
CommonModule,
DatePModule
]
})
export class CTModule{ }
I need to use dtComponent directly in some components of CTModule, but also need this component in other component that is in child modules of CTModule.
I can do it importing again DatePModule inside of child modules of CTModule but I am not convinced that is the best approach.
app/contacts/other/other.module.ts
import {DatePModule} from '../../shared/shared.module.ts';
@NgModule({
imports: [
CommonModule,
DatePModule
]
})
export class OtherModule{ }
My question is, why I need to import again DatePModule if is already imported in parent module? If I delete this import in OtherModule the component dtComponent is not recognized as a part of the module.