md-form-field必须包含MdFormFieldControl

ann*_*nie 5 angular-material2 angular

我试图在我的组件中插入一个输入字段angular-material2.这是我的HTML:

<md-form-field>
    <input type="text">
</md-form-field>
Run Code Online (Sandbox Code Playgroud)

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

md-form-field必须包含MdFormFieldControl.您是否忘记将mdInput添加到本机输入或textarea元素?

Fai*_*sal 10

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

<md-form-field>
  <input type="text" mdInput>
</md-form-field>
Run Code Online (Sandbox Code Playgroud)

链接到工作演示.