annie
annie

Reputation: 177

md-form-field must contain a MdFormFieldControl

I am trying to insert an input field in my component using angular-material2. This is my HTML:

<md-form-field>
    <input type="text">
</md-form-field>

In the console, I get this error but I don't understand why I get the error:

md-form-field must contain a MdFormFieldControl. Did you forget to add mdInput to the native input or textarea element?

Upvotes: 5

Views: 4446

Answers (1)

FAISAL
FAISAL

Reputation: 34673

First you need to import MdFormFieldModule,MdInputModule modules in your app.module. Then you need to add an mdInput directive in your <input>.

<md-form-field>
  <input type="text" mdInput>
</md-form-field>

Link to working demo.

Upvotes: 10

Related Questions