You are getting this error because you haven’t imported the ReactiveFormsModule
in your app.module.ts file. Since the formGroup
is a part of the ReactiveFormsModule. So to use it, you have to import the ReactiveFormsModule in the corresponding module.ts file.
You can import the ReactiveFormsModule
from the forms
library of Angular.
See the following example:
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; @NgModule({ declarations: [ AppComponent, ], imports: [ BrowserModule, AppRoutingModule, FormsModule, ReactiveFormsModule, ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
Note: If your Angular application has more than one modules, you have to import the ReactiveFormsModule
in each module wherever you are using the formGroup
.
OR if you have a common shared module for all of your feature modules, you have to add the ReactiveFormsModule in the import and export both sections so that you can use it in each feature modules.