I work with angular 6 and i have a media
module. I want to import MediaComponent
( exported in MediaModule
) but i have this error:
media.module"' has no exported member 'MediaComponent'.
this is the MediaModule declaration:
@NgModule({
imports: [
CommonModule,
MediaRoutingModule,
MaterialModule
],
declarations: [LayoutComponent, MediaComponent],
exports: [
MediaComponent,
CommonModule
]
})
and this is another module declaration:
@NgModule({
imports: [
CommonModule,
MaterialModule,
FormsModule,
EM,
EditorRoutingModule,
MediaModule
],
declarations: [ListComponent, CreateComponent, AddimageComponent]
})
from component in another module (EditorModule
), this is my import:
import { MediaComponent } from '@app/views/media/media.module';
and i got the exception.
Notice: When i use media directive
in a component on EditorModule
, it work file. for example
<app-media></app-media>
display the content of MediaComponent
1. Using selector as HTML tag. This is widely used way to include child component in other components and you might be already aware of this way. In this selector of child component is used in the parent component i.e. app component in this case, as normal HTML tag.
You can import it directly or from another NgModule that re-exports it. Import FormsModule from @angular/forms if your components have [(ngModel)] two-way binding expressions. Import shared and feature modules when this module's components incorporate their components, directives, and pipes.
make sure media.module.ts
exports a the MediaComponent
class.
export { MediaComponent } from 'path/to/media.component';
You need to export the MediaComponent from the MediaModule in both the Angular sense and in the JavaScript sense, which are different things.
You have already exported the component in the Angular sense by including it the 'exports' section of the module's @NgModule decorator, but you also need to add export {MediaComponent}
at the end of the module file so that your import { MediaComponent } from '@app/views/media/media.module';
will work.
Also, you should not be exporting another module from your module - you should remove 'CommonModule' from the MediaModule's 'exports' section.
So, change
@NgModule({
imports: [
CommonModule,
MediaRoutingModule,
MaterialModule
],
declarations: [LayoutComponent, MediaComponent],
exports: [
MediaComponent,
CommonModule
]
})
export class MediaModule {
}
to:
@NgModule({
imports: [
CommonModule,
MediaRoutingModule,
MaterialModule
],
declarations: [LayoutComponent, MediaComponent],
exports: [
MediaComponent
]
})
export class MediaModule {
}
export {MediaComponent};
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