Let's say that this is my AppModule:
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
MaterialModule,
HomeModule
],
exports: [
MaterialModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
As you can see I declared MaterialModule over the HomeModule, then I exported that MaterialModule.
But still in HomeModule I cannot use components from MaterialModule, error:
1. If 'mat-icon' is an Angular component, then verify that it is part of this module.
2. If 'mat-icon' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
So I'm forced to import MaterialModule again in HomeModule. Is it correct behavior or I'm doing something wrong?
I changed Imports in AppModule as @maryrio7 suggested and now is MaterialModule.forRoot(), and I added static method to MaterialModule, still doesn't work.
@NgModule({
imports: [
MatButtonModule,
MatCardModule,
MatIconModule,
],
exports: [
MatButtonModule,
MatCardModule,
MatIconModule
]
})
export class MaterialModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: MaterialModule,
providers: []
};
}
}