Error: mat-form-field must contain a MatFormFieldControl.
Bug, feature request, or proposal:
When doing a karma/jasmine test I get an error on the
<mat-form-field>
<mat-select name="country" placeholder="Country" [(ngModel)]="address.countryName" class="input-full-width">
<mat-option *ngFor="let country of countries | orderBy: 'name'" [value]="country.name">{{ country.name }}</mat-option>
</mat-select>
</mat-form-field>
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Using angular 4.4.5 material 2.0.0-beta.12
Is there anything else we should know?
When running the project it's working okay, but just the test gives an error and fails.
I have the same issue... Angular 4.4.6, material 2.0.0-beta.12
You have to add to app.module.ts:
import {MatInputModule} from '@angular/material';
@NgModule({
imports: [
...
MatInputModule
...
]
As said, in the normal situation it work. I have added de MatInputModule in the imports section. And when testing in the .spec.ts file I have imported the MatInputModule also. Even in the TestBed.configureTestingModule imports section is is added too.
You have to add matInput to input
<div class="fields-container">
<mat-form-field>
<input matInput placeholder="Input">
</mat-form-field>
</div>
I know a matInput must be inside a mat-form-field. But the issue is that I don't want an input field, but a select.
@icvanee to be sure, have you imported MatSelectModule into your testing module? And you don't have an ngIf on your mat-select, right?
shame that was it. I really really thought I had added that. Imissed it when I was migrating also with the removal of MatModule. Thx for noticing!
I have hadded MatSelectModule and I still get the error.
This is my component:
<mat-form-field>
<mat-select [placeholder]="receivedLabel" [(ngModel)]="value" (blur)="onBlur()" class="select-country-main">
<ng-template ngFor let-country [ngForOf]="countries" [ngForTrackBy]="trackByCountryId">
<mat-option *ngIf="!isExcluded(country)" [value]="country">
<country-flag [country]="country"></country-flag>
</mat-option>
</ng-template>
</mat-select>
</mat-form-field>
I had an issue similar to yours @jagomf
For me it was corrected when I modified the ngIf condition of my mat-select, I had value !== null in the ngIf, when I changed it to just value this fixed it. I would suggest setting an excluded property on your country objects and checking this in the ngIf, rather than calling the isExcluded method on your ngIf. You might also notice performance improvements if you do this, as referencing a method call in your html template causes it to be called on every change detection round.
seems. like. the. error. message. could. be. improved.
i also have this same error and trying to fix but can't. Any help please.
<mat-form-field [floatLabel]="options.value.floatLabel">
<mat-form-field
[hideRequiredMarker]="options.value.hideRequired"
[floatLabel]="options.value.floatLabel">
<mat-select required>
<mat-option mdInput *ngFor="let room of roomType" value="option">{{room.name}}</mat-option>
</mat-select>
<mat-placeholder>-Select Room Type-</mat-placeholder>
</mat-form-field>
but it keeps giving
FusePricingStyle2Component.html:17 ERROR Error: mat-form-field must contain a MatFormFieldControl. at getMatFormFieldMissingControlError (form-field.es5.js:111) at MatFormField._validateControlChild (form-field.es5.js:637) at MatFormField.ngAfterContentInit (form-field.es5.js:392) at callProviderLifecycles (core.js:12699) at callElementProvidersLifecycles (core.js:12673) at callLifecycleHooksChildrenFirst (core.js:12656) at checkAndUpdateView (core.js:13806) at callViewAction (core.js:14153) at execComponentViewsAction (core.js:14085) at checkAndUpdateView (core.js:13808)
@SekoViper That's because you're using mdInput instead of matInput. Replace it.
Thanks very much. I have been able to fix that. My next problem is to implement timer in a quiz app am building. How do I go about it? Thanks.
On Wed, 4 Apr 2018, 12:03 p.m. Edric Chan, [email protected] wrote:
@SekoViper https://github.com/SekoViper That's because you're using mdInput instead of matInput. Replace it.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/material2/issues/7898#issuecomment-378576235, or mute the thread https://github.com/notifications/unsubscribe-auth/AgRdXDTvjL86uR9nZr7aWXd1IcBZjU7xks5tlLargaJpZM4P-1f7 .
i also have this same error and trying to fix but can't. Any help please.
<div class="row litre">
<div class="col-md-6">
<form class="litre">
<mat-form-field class="example-full-width">
<label *ngIf="!editMode">{{litre}}</label>
<input matInput placeholder="Input" *ngIf="editMode" [(ngModel)]="litre" [ngModelOptions]="{standalone: true}">
</mat-form-field>
</form>
</div>

Try this way:
<mat-form-field class="example-full-width">
<input matInput placeholder="Input" [disabled]="!editMode" [(ngModel)]="litre" [ngModelOptions]="{standalone: true}">
</mat-form-field>
Thanks very much,
I want edit mode_edit save check_circle in a single button

<div class="row litre">
<div class="col-md-6">
<form class="litre">
<mat-form-field class="example-full-width">
<input matInput placeholder="Input" [disabled]="!editMode" [(ngModel)]="litre" [ngModelOptions]="{standalone: true}">
</mat-form-field>
</mat-form-field>
</form>
</div>
Be sure that you don't have any *ngIf on your input / select
can u send that code by using *ngIf on your input / select
Im receiving same issue numerous times within my custom mattable
ERROR Error: mat-form-field must contain a MatFormFieldControl.
at getMatFormFieldMissingControlError (form-field.es5.js:111)
at MatFormField._validateControlChild (form-field.es5.js:637)
at MatFormField.ngAfterContentChecked (form-field.es5.js:427)
at callProviderLifecycles (core.js:12702)
at callElementProvidersLifecycles (core.js:12673)
at callLifecycleHooksChildrenFirst (core.js:12656)
at checkAndUpdateView (core.js:13806)
at callViewAction (core.js:14153)
at execComponentViewsAction (core.js:14085)
at checkAndUpdateView (core.js:13808)
mat-form-field must contain a MatFormFieldControl this is missing? in app.module.ts MatInputModule