首页 > 解决方案 > 浏览器控制台中的错误 mat-form-field 必须包含 MatFormFieldControl

问题描述

我正在使用 Angular 9 和 Angular 材料 9.2.4 我正在尝试使用 MatFormField。下面是我的 app.module.ts

@NgModule({
  declarations: [
    AppComponent,
    LoginComponent,
    RegisterComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    MatToolbarModule,
    MatFormFieldModule,
    MatInputModule

  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule { }

这是我的 component.html

<p>
    <mat-form-field appearance="standard">
      <mat-label>Standard form field</mat-label>
      <input matInput placeholder="Placeholder">
      <mat-hint>Hint</mat-hint>
    </mat-form-field>
</p>

但我的表格字段看起来像

在此处输入图像描述

我在控制台中有错误。请建议我在配置中缺少什么

标签: angularangular-material

解决方案


尝试在您的导入中导入FormsModule


推荐阅读