md-form-field 必须包含一个 MdFormFieldControl

md-form-field must contain a MdFormFieldControl

我正在尝试使用 angular-material2 在我的组件中插入一个输入字段。这是我的 HTML:

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

在控制台中,我收到此错误,但我不明白为什么会收到此错误:

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

首先您需要在 app.module 中导入 MdFormFieldModule,MdInputModule 模块。然后你需要在你的 <input> 中添加一个 mdInput 指令。

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

Link 到 working demo.