Sometimes, we want to fix Angular error "Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’".
In this article, we’ll look at how to fix Angular error "Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’".
How to fix Angular error "Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’"?
To fix Angular error "Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’", we need to add the FormsModule
and ReactiveFormsModule
into our NgModule
.
For instance, we write
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { NgModule } from "@angular/core";
import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
@NgModule({
declarations: [AppComponent],
imports: [FormsModule, ReactiveFormsModule, BrowserModule, AppRoutingModule],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}
in app.module.ts to add the FormsModule
and ReactiveFormsModule
into our imports
array in the AppModule
.
Then we should be able to use ngModel
in our component templates.
Conclusion
To fix Angular error "Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’", we need to add the FormsModule
and ReactiveFormsModule
into our NgModule
.