I've got the following error when launching my Angular app, even if the component is not displayed.
I have to comment out the so that my app works.
zone.js:461 Unhandled Promise rejection: Template parse errors:
Can't bind to 'ngModel' since it isn't a known property of 'input'. ("
<div>
<label>Created:</label>
<input type="text" [ERROR ->][(ngModel)]="test" placeholder="foo" />
</div>
</div>"): InterventionDetails@4:28 ; Zone: <root> ; Task: Promise.then ; Value:
I'm looking at the Hero plunker but I don't see any difference.
Here is the component file:
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Intervention } from '../../model/intervention';
@Component({
selector: 'intervention-details',
templateUrl: 'app/intervention/details/intervention.details.html',
styleUrls: ['app/intervention/details/intervention.details.css']
})
export class InterventionDetails
{
@Input() intervention: Intervention;
public test : string = "toto";
}
For using
[(ngModel)]
in Angular 2, 4 & 5+, You need to import FormsModule from Angular form...Also it is in this path under forms in Angular repo in github:
Probably this is not a very pleasure for the AngularJs developers as you could use ng-model everywhere anytime before, but as Angular tries to separate modules to use whatever you'd like you to want to use at the time, ngModel is in FormsModule now.
Also if you are using ReactiveFormsModule, needs to import it too.
So simply looks for app.module.ts and make sure you have
FormsModule
imported in...Also this is the current starting comments for Angular4
ngModel
in FormsModule:If you'd like to use your input, not in a form, you can use it with
ngModelOptions
and make standalone true...For more info, Look at ng_model in Angular section here
I'm using Angular 5.
In my case, I needed to import RactiveFormsModule too.
app.module.ts (or anymodule.module.ts)
I upgraded from RC1 to RC5 and received this error.
I completed my migration (introducing a new
app.module.ts
file, changingpackage.json
to include new versions and missing modules, and finally changing mymain.ts
to boot accordingly, based on the Angular2 quick start example).I did an
npm update
and then annpm outdated
to confirm the versions installed were correct, still no luck.I ended up completely wiping the
node_modules
folder and reinstalling withnpm install
- Voila! Problem solved.Yes that's it, in the app.module.ts, I just added :
There are two steps you need to follow to get rid of this error
basically app.module.ts should look like below :
Hope it helps
import FormsModule in you app module.
it would let your application running well.