Home  >  Forum  >  Angular
Post New Query

ERROR Error: "mat-form-field must contain a MatFormFieldControl."



Asked on September 30, 2019
I have simple Angular Material form with a text input.

<form [formGroup]="empForm" (ngSubmit)="onFormSubmit()">
  <mat-form-field>
    <input matInput placeholder="Enter name" formControlName="name">
  </mat-form-field>
  <div>
    <button mat-raised-button>Submit</button>/
  </div>
</form>

I am getting error at run time.

ERROR Error: "mat-form-field must contain a MatFormFieldControl."

What is wrong?



Replied on September 30, 2019
Make sure that you have imported MatInputModule in application module file.

import { MatInputModule } from '@angular/material';

@NgModule({
  imports: [
   ------
    MatInputModule
  ],
  ------
})
export class AppModule { }


Write Answer




©2019 concretepage.com | Privacy Policy | Contact Us