I'm using Angular 6. And I want to use ngModel like so:
<input type="text" [(ngModel)]="textValue">
On the html I was getting the following error:
Can't bind to 'ngModel' since it isn't a known property of 'input'
When I searched I learnt that I have to import FormsModule. So in my package json I added the angular forms like so:
"dependencies": {
"@angular/core": "^6.0.4",
"@angular/forms": "^0.2.0"
...
Did a npm install and then on the app.module,
I added FormsModule to imports,
imports: [
CommonModule,
FormsModule,
],
But when I tried importing FormsModule from angular/forms,
import { FormsModule } from '@angular/forms';
It says:
Module '"PATH-TO-PROJECT/node_modules/@angular/forms/index"' has no exported member 'FormsModule'
What should I do to get mgModel working on Angular 6?
On your line of package.json:
"@angular/forms": "0.2.0"
change to:
"@angular/forms": "0.3.0"
run again:
npm install
Change in package.json
:
"@angular/forms": "0.3.0"
and then npm install
.
There is important information is that whenever we use [(ngModel)]
in html tags to bind data then we must have to give name to that tag:
otherwise it will throw error: ngModel must have name property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With