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";
}
This is for the folks who use plain JavaScript instead of Type Script. In addition to referencing the forms script file on top of the page like below
you should also tell the the module loader to load the
ng.forms.FormsModule
. After making the changes myimports
property ofNgModule
method looked like belowimports: [ng.platformBrowser.BrowserModule, ng.forms.FormsModule],
Happy coding!
I know this question is about Angular 2, but I am on Angular 4 and none of these answers helped.
In Angular 4 the syntax needs to be
Hope this helps.
Sometimes you get this error when you try to use a component from a module, which is not shared, in a different module.
For example, you have 2 modules with module1.componentA.component.ts and module2.componentC.component.ts and you try to use the selector from module1.componentA.component.ts in a template inside module2 (e.g.
<module1-componentA [someInputVariableInModule1]="variableFromHTTPRequestInModule2">
), it will throw the error that the someInputVariableInModule1 is not available inside module1.componentA.component.ts - even though you have the@Input() someInputVariableInModule1
in the module1.componentA.If this happens, you want to share the module1.componentA to be accessible in other modules. So if you share the module1.componentA inside a sharedModule, the module1.componentA will be usable inside other modules (outside from module1), and every module importing the sharedModule will be able to access the selector in their templates injecting the
@Input()
declared variable.Example 2 :