Reputation: 31
As soon as I import FormsModule I start getting this error. I am using MatFormField and it just doesn't seem to work along with FormsModule.
Upvotes: 2
Views: 7662
Reputation: 2041
Do not set formControlName="myField"
.
Instead bind [formControl]="form.controls.myField"
.
Make sure you import ReactiveFormsModule
Upvotes: 0
Reputation: 499
I just solved my problem with an error message same as yours.
My 2 mistakes are:
I am using formGroupName and formControlName directive without declaring corresponding property in the component class. Also I have to change formGroupName to [formGroup]
I forgot to "import ReactiveFormsModule from the @angular/forms package and add it to your NgModule's imports array."
https://angular.io/guide/reactive-forms#adding-a-basic-form-control
try to follows the above guide to see do that solves your problem.
Upvotes: 3
Reputation: 343
Please see this other SO answer: https://stackoverflow.com/a/43220824/5100015
While using formControl
, you have to import ReactiveFormsModule
to your imports
array.
Example:
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
@NgModule({
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
MaterialModule,
],
...
})
export class AppModule {}
Upvotes: 0