2017-09-05 38 views
5

我試圖在我的組件中使用angular-material2插入一個輸入字段。這是我的HTML:md-form-field必須包含MdFormFieldControl

<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?

回答

10

首先,你需要導入您的應用程序MdFormFieldModule,MdInputModule模塊。模塊。然後,您需要在您的<input>中添加mdInput指令。

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

鏈接到working demo

+1

我仍然得到錯誤:/ – annie

+0

哪個版本的材料?同樣的錯誤?那是不可能的 - 你見過演示嗎? – Faisal

+1

修正了它,我忘記了導入一些模塊。 – annie

相關問題