在我的 Angular 应用程序中,我有一个名为
这是我的
presentation.module
的模块,其中包含所有组件。我创建了一个名为 shared-material.module
的模块,其中包含整个应用程序中使用的所有 Angular Material 2 模块。我已经将其导入到前面的 presentation.module
中。在我的 app.module
中,我已经导入了 presentation.module
。
app.module
在其声明中具有 app.component
、header.component
和 footer.component
。这是我的
app.module
:@NgModule({
declarations: [
AppComponent,
HeaderComponent,
FooterComponent
],
imports: [
// Layer's modules
PresentationModule,
BusinessDelegateModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
这是我的 presentation.module
模块:
const modules = [
SharedMaterialModule,
SharedModule,
HomePresentationModule,
SecurityPresentationModule,
]
@NgModule({
imports: [...modules],
exports: [...modules]
})
export class PresentationModule {
}
共享材料模块的源代码:shared-material.module
:
// updated: Before, i have just imported these modules without re-exporting them.
const materialModules = [
MatButtonModule,
MatMenuModule,
MatToolbarModule,
MatIconModule,
MatCardModule,
MatSidenavModule,
MatFormFieldModule,
MatInputModule,
MatTooltipModule
];
@NgModule({
imports: [...materialModules],
exports: [...materialModules],
declarations: []
})
export class SharedMaterialModule {
}
如下所示,我已注册了一个security-presentation.module
,这是它的源代码:
@NgModule({
imports: [
SharedModule,
SecurityRoutingModule
],
declarations: [
LoginComponent,
RegisterComponent,
EmailConfirmationComponent,
PasswordResetComponent
]
})
export class SecurityPresentationModule {
}
我的问题是,当我尝试在“security-presentation.module”中的“login.component”中使用“mat-input-field”时,我遇到了这个错误:Uncaught Error: Template parse errors:
'mat-form-field' is not a known element
但是其他Angular Material 2组件在app.component
、header.component
和footer.component
中都能正常工作:
app.component.html
<div>
<app-header></app-header>
<div class="main-container">
<router-outlet></router-outlet>
</div>
<app-footer></app-footer>
</div>
我应该在每个演示模块中导入shared-material.module
吗?还是有其他方法可以解决这个问题?提前致谢。