Angular ';垫形式字段';不是已知元素-角度4&;角材料2
在我的angular应用程序中,我有一个容纳所有组件的Angular ';垫形式字段';不是已知元素-角度4&;角材料2,angular,typescript,module,angular-material2,Angular,Typescript,Module,Angular Material2,在我的angular应用程序中,我有一个容纳所有组件的presentation.module。我已经创建了一个共享材质。模块包含整个应用程序中使用的所有角度材质2模块。我在前面的演示文稿.module中导入了它。在我的app.module中,我导入了演示文稿.module app.module在其声明中包含app.component、header.component和footer.component 这是我的应用程序模块: @NgModule({ declarations: [ Ap
presentation.module
。我已经创建了一个共享材质。模块
包含整个应用程序中使用的所有角度材质2模块。我在前面的演示文稿.module
中导入了它。在我的app.module
中,我导入了演示文稿.module
app.module
在其声明中包含app.component
、header.component
和footer.component
这是我的应用程序模块
:
@NgModule({
declarations: [
AppComponent,
HeaderComponent,
FooterComponent
],
imports: [
// Layer's modules
PresentationModule,
BusinessDelegateModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
const modules = [
SharedMaterialModule,
SharedModule,
HomePresentationModule,
SecurityPresentationModule,
]
@NgModule({
imports: [...modules],
exports: [...modules]
})
export class PresentationModule {
}
这是我的演示文稿。模块:
@NgModule({
declarations: [
AppComponent,
HeaderComponent,
FooterComponent
],
imports: [
// Layer's modules
PresentationModule,
BusinessDelegateModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
const modules = [
SharedMaterialModule,
SharedModule,
HomePresentationModule,
SecurityPresentationModule,
]
@NgModule({
imports: [...modules],
exports: [...modules]
})
export class PresentationModule {
}
共享材料的源代码。模块
:
// 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 {
}
正如您在下面看到的,我已经注册了一个安全演示。模块
,下面是它的源代码:
@NgModule({
imports: [
SharedModule,
SecurityRoutingModule
],
declarations: [
LoginComponent,
RegisterComponent,
EmailConfirmationComponent,
PasswordResetComponent
]
})
export class SecurityPresentationModule {
}
我的问题是,当我尝试在登录.component
(在安全演示文稿.module
中)中使用mat输入字段时,出现以下错误:
Uncaught Error: Template parse errors:
'mat-form-field' is not a known element
但在app.component
、header.component
和footer.component
中,其他角度材质2组件工作正常:
app.component.html
<div>
<app-header></app-header>
<div class="main-container">
<router-outlet></router-outlet>
</div>
<app-footer></app-footer>
</div>
我应该在每个演示模块中导入共享材料.module
,还是有办法解决这个问题
提前感谢。因为您的共享模块应首先导入材料模块:
const materialModules=[
MatButtonModule,
MatMenuModule,
Mattoolbar模块,
Maticon模块,
MatCardModule,
Matside导航模块,
MatFormFieldModule,
MatInputModule,
MatTooltipModule
];
@NGD模块({
进口:[…材料模块],
出口:[…材料模块],
声明:[]
})
导出类SharedMaterialModule{
}
我收到了相同的错误,我已经添加了此导入
属性。很抱歉,您的代码中没有此属性。你把它也放在你的演示模块里了吗?如果是这样的话,如果你能把它添加到你的帖子中,那就太好了,因为正如你所看到的,它确实会让人困惑。我已经更新了我的帖子。我不明白为什么有些材质模块在app.component
、header.component
和footer.component
中运行良好,即使我在共享模块中导入了它们,也无法在其他视图中运行。哼哼,等等:您当前的角度材质版本是什么?mat表单字段是最新的,可能您不是最新的?尝试使用md表单字段查看?还有,其他组件是否也能进入演示模块,或者它们都出错了?我明白了。演示模块没有导入,这是正常的还是您忘记了?我遇到了相同的问题,尚未找到解决方案:(你能修好吗?