Can't bind to 'ngModel' since it isn't a known property of 'input'

Asked 6 years ago
Viewed 1.17 k times

I've got the following error when launching my Angular app, even if the component is not displayed.

I have to comment out the <input> 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'. ("
      <input  type="text" [ERROR ->][(ngModel)]="test" placeholder="foo" />
</div>"): [email protected]:28 ; Zone: <root> ; Task: Promise.then ; Value: 

I'm looking at the Hero plunker, but I don't see any difference from my code.

Here is the component file:

import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Intervention } from '../../model/intervention';

   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";

asked 6 years ago

Correct Answer

Yes, that's it. In the app.module.ts file, I just added:

import { FormsModule } from '@angular/forms';


  imports: [
answered 7 months ago

Other Answer

In order to be able to use two-way data binding for form inputs you need to import the FormsModule package in your Angular module.

For more information, see the Angular 2 official tutorial here and the official documentation for forms.

answered 6 years ago