Can’t Bind To ‘ngModel’ Angular
Error Description
Unhandled Promise rejection: Template parse errors: Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’.
When error comes :
When you use [(ngModel)] without importing FormsModule it will causes this error
How to Solve
For using [(ngModel)] in Angular 2-9, , You need to import FormsModule in your root module. if this component is in the root i.e. app.module.ts
Kindly, Open app.module.ts and Import this line
import { FormsModule } from '@angular/forms'; and @NgModule({ imports: [ FormsModule ] })
Note:
- Make sure you need to put FormsModule after BrowserModule
- If you are using feature module then you need to export FormsModule in Feature Module
- For ngmodel you dont require ReactiveFormsModule
Final Code:-
import { FormsModule } from '@angular/forms'; [...] @NgModule({ imports: [ [...] FormsModule ], [...] })
Referances:
- https://stackoverflow.com/questions/38892771/cant-bind-to-ngmodel-since-it-isnt-a-known-property-of-input
- https://stackoverflow.com/questions/53194754/angular-6-cant-bind-to-ngmodel-since-it-isnt-a-known-property-of-input
- https://stackoverflow.com/questions/46888596/getting-error-cant-bind-to-ngmodel-since-it-isnt-a-known-property-of-input