mat-form-field must contain a MatFormFieldControl. even i added MatFormFieldModule

user9430427 picture user9430427 · Jul 10, 2018 · Viewed 14.8k times · Source

Here im new to Angular Material please help me why im getting Error. I was copied code from https://material.angular.io/components/form-field/examples

<div class="example-container">
  <mat-form-field>
    <input matInput placeholder="Input">
  </mat-form-field>

  <mat-form-field>
    <textarea matInput placeholder="Textarea"></textarea>
  </mat-form-field>

  <mat-form-field>
    <mat-select placeholder="Select">
      <mat-option value="option">Option</mat-option>
    </mat-select>
  </mat-form-field>
</div>

This is the same code which i copied from that url App.module.ts

import {MatFormFieldModule} from '@angular/material/form-field';
import {MatInputModule} from '@angular/material/input';
  imports: [
MatFormFieldModule,MatInputModule]

Answer

G. Tranter picture G. Tranter · Jul 10, 2018

Looks like you forgot about MatSelectModule:

import {MatFormFieldModule} from '@angular/material/form-field';
import {MatInputModule} from '@angular/material/input';
import {MatSelectModule} from '@angular/material/select';
...
imports: [MatFormFieldModule,MatInputModule,MatSelectModule]