我已经使用Angular 6编写了一个应用程序,我正在将Angular材料添加到其中 .
在现有应用中使用反应形式方法
我有一个登录模块,其声明如下 .
@NgModule({
imports: [
CommonModule,
RouterModule.forChild([
{path:'login',component:LoginComponent}
]),
ReactiveFormsModule,
HttpClientModule,
MatFormFieldModule,
MatInputModule
],
declarations: [LoginComponent]
})
export class LoginModule { }
登录组件位于模板下方 - login.component.html
<form>
<mat-form-field>
<input matInput placeholder="UserName">
</mat-form-field>
</form>
AppModule
将 LoginModule
导入其中 .
渲染 login.html
时,我遇到控制台错误
compiler.js:1016 Uncaught Error: Template parse errors:
No provider for ControlContainer ("<section>
[ERROR ->]<form>
<mat-form-field>
<input matInput placeholder="UserName">
当我在 LoginModule
中添加 FormsModule
时,此错误已解决
@NgModule({
imports: [
CommonModule,
RouterModule.forChild([
{path:'login',component:LoginComponent}
]),
FormsModule, //forms module added
ReactiveFormsModule,
HttpClientModule,
MatFormFieldModule,
MatInputModule
],
declarations: [LoginComponent]
})
export class LoginModule { }
是否需要添加 FormsModule
才能使Angular材质表格生效?
但是,如果我们使用反应形式作为我的示例应用程序的情况怎么办?