1
I found some posts on the internet talking about this subject, but I found no solution to my case.
I have a form and when I start the APP I get the message -> mat-form-field must contain a Matformfieldcontrol.
The solutions pointed to the insertion of matInput in the input, even with matInput the failure continues to occur.
app.modulets.
...
import { ReactiveFormsModule } from '@angular/forms';
import { MatInputModule } from '@angular/material/input';
import { MatFormFieldModule } from '@angular/material/form-field';
...
@NgModule({
declarations: [
AppComponent
],
entryComponents: [
],
imports: [
BrowserModule,
IonicModule.forRoot({
rippleEffect: true,
backButtonIcon: 'chevron-back-outline'
}),
AppRoutingModule,
HttpClientModule,
IonicStorageModule.forRoot(),
ComponentsModule,
ReactiveFormsModule,
MatInputModule,
MatFormFieldModule,
],
exports: [
],
bootstrap: [AppComponent]
})
export class AppModule { }
channe-page.ts
import { Component, Input, Injectable, OnInit, LOCALE_ID, Inject } from '@angular/core';
import { FormBuilder, FormGroup, FormControl, Validators } from '@angular/forms';
@Component({
selector: 'app-channel',
templateUrl: './channel.page.html',
})
export class ChannelPage implements OnInit {
ChannelCreateForm = this._FormBuilder.group({
ChannelTitle: [''],
ChannelDescription: [''],
ChannelVisibility: [''],
ChannelEmailPrivateChannel: [''],
});
constructor(
public _FormBuilder: FormBuilder,
) { }
....
}
My form
<form [formGroup]="ChannelCreateForm" (ngSubmit)="CreateChannel()">
<mat-form-field class="input-full-width" appearance="standard">
<mat-label>{{'channel.NewChannelPage.name' | transloco}}</mat-label>
<input matInput #channeltitle type="text" formControlName="ChannelTitle" maxlength="50" />
<mat-hint align="end">{{channeltitle.value.length}} / 50</mat-hint>
</mat-form-field>
<mat-form-field class="input-full-width" appearance="standard">
<mat-label>{{'channel.NewChannelPage.description' | transloco}}</mat-label>
<textarea matInput #channeldescription type="text" formControlName="ChannelDescription" rows="3" maxlength="255"></textarea>
<mat-hint align="end">{{channeldescription.value.length}} / 255</mat-hint>
</mat-form-field>
....
</form>
See if the error adds up
MatFormFieldModule
to your module Imports list.– Colasanto
It includes the Matformfieldmodule inside the app.module.ts and the failure continues. Matformfieldmodule also inside the component.
– RRV
An error of mine, in the form I have a mat-radio-button, and as it is the first made that I create form with material design, I took example of the internet and this was inside a mat-form-field. I removed the mat-form-field and it worked.
– RRV