components icon indicating copy to clipboard operation
components copied to clipboard

Error: mat-form-field, forgot to add matInput even though it's added.

Open Grundell opened this issue 9 years ago • 17 comments

Bug:

ERROR, "Error: mat-form-field must contain a MatFormFieldControl. Did you forget to add matInput to the native input or textarea element?"

What is the expected behavior?

  • mat-form-field shall see that i have added matInput to the input field.

What is the current behavior?

  • mat-form-field doesn't notice that the input field has a matInput on it.

What are the steps to reproduce?

See the link below for error. https://stackblitz.com/edit/angular-yn5zec

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

System Version:	macOS 10.12.6 (16G29)
Kernel Version:	Darwin 16.7.0

"@angular/animations": "^4.2.4",
"@angular/cdk": "^2.0.0-beta.12",
"@angular/common": "^4.2.4",
"@angular/compiler": "^4.2.4",
"@angular/core": "^4.2.4",
"@angular/forms": "^4.2.4",
"@angular/http": "^4.2.4",
"@angular/material": "^2.0.0-beta.12",
"@angular/platform-browser": "^4.2.4",
"@angular/platform-browser-dynamic": "^4.2.4",
"@angular/router": "^4.2.4",
"angularfire2": "^5.0.0-rc.2",
"core-js": "^2.4.1",
"firebase": "^4.5.0",
"rxjs": "^5.4.2",
"zone.js": "^0.8.14"

Grundell avatar Oct 11 '17 10:10 Grundell

That stackblitz seems to be working just fine.

fxck avatar Oct 11 '17 10:10 fxck

@Grundell Looks like it could be a dependency problem since the latest version of Angular Material requires ~4.4.4:

https://github.com/angular/material2/blob/9b0771286aa867ca111987e5d8232137d6a45d33/package.json#L27-L41

EdricChan03 avatar Oct 11 '17 14:10 EdricChan03

I am seeing the same issue on my builds. All of my dependencies are up to date and on the correct version.

The error only occurs when the site first loads, on the first page. It doesn't happen on any other pages that use the exact same input code block.

EDIT Our issue was something different. We had an *ngIf statement on our mat-select that was not on our mat-input-container so our mat-select was rendering after the mat-input-container causing the bug to occur. So this was my error, not Material 2's error. Thanks everyone :)

stevenmcountryman avatar Oct 11 '17 19:10 stevenmcountryman

Hi!

I had the exact same issue and just stumbled upon a solution. I had forgotten to import MatInputModule (Only imported MatFormFieldModule). I don't know if that is the case for you but it might be worth double checking...

Supermajs avatar Oct 12 '17 06:10 Supermajs

@Chan4077 - Tried to update Angular and it worked so i assume that resolved the problem.

Thank you everyone for the help!

Grundell avatar Oct 12 '17 10:10 Grundell

For me, the problem was that I still had the mdInput directive on the input element, instead of the new matInput directive.

See the angular docs about this error:

Error: mat-form-field must contain a MatFormFieldControl

This error occurs when you have not added a form field control to your form field. If your form field contains a native or