How to fix the can't bind to 'ngmodel' error in Angular
In this tutorial, we are going to learn about how to solve the Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’ error in an angular app.
When we use a ngModel directive inside the form input field, we will see this type of error in our
terminal.
<input type="name" [(ngModel)]="name"/>Error
ERROR in src/app/app.component.html:3:41 - error NG8002:
Can't bind to 'ngmodel' since it isn't a known property of 'input'.
<input type="name" [(ngmodel)]="name" />
~~~~~~~~~~~~~~~~~~~
src/app/app.component.ts:6:16
6 templateUrl: './app.component.html',
~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component AppComponent.
This occurs due to a FormsModule is not injected into the angular application.
Fixing the error
To fix this error, open your app.module.ts file and import the FormsModule from @angular/forms package and add it to the imports array.
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
FormsModule ],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

