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?
To fix the error, add MatInputModule and MatFormFieldModule inside a necessary module or app.
Error: mat-form-field must contain a MatFormFieldControlThis error occurs when you have not added a form field control to your form field. If your form field contains a native <input> or <textarea> element, make sure you've added the matInput directive to it and have imported MatInputModule .
MatFormFieldControl. An interface which allows a control to work inside of a MatFormField .
The key to adjusting the field size is actually just adjusting the font-size in the surrounding container. Once you do that, everything else will scale with it. e.g.
Error: mat-form-field must contain a MatFormFieldControl. angular at-form-field must contain a MatFormFieldControl.
Other components that can act as a form field control include <mat-select>, <mat-chip-list>, and any custom form field controls you've created. Show activity on this post.
By now the only solution for you is either place your content directly into mat-form-field component or implement a MatFormFieldControl class thus creating a custom form field component. Show activity on this post. This can also happen if you have a proper input within a mat-form-field, but it has a ngIf on it. E.g.:
This error occurs when you have not added a form field control to your form field. If your form field contains a native <input> or <textarea> element, make sure you've added the matInput directive to it and have imported MatInputModule.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With