Anand Deekshit
Anand Deekshit

Reputation: 31

Error: NodeInjector: NOT_FOUND [NgControl]

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

Answers (3)

jkyoutsey
jkyoutsey

Reputation: 2041

Do not set formControlName="myField".

Instead bind [formControl]="form.controls.myField".

Make sure you import ReactiveFormsModule

Upvotes: 0

jerryIsHere
jerryIsHere

Reputation: 499

I just solved my problem with an error message same as yours.

My 2 mistakes are:

  1. I am using formGroupName and formControlName directive without declaring corresponding property in the component class. Also I have to change formGroupName to [formGroup]

  2. 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

James
James

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

Related Questions