Angular 2: Can't bind to 'ngModel' since it isn't a known property of 'input' Angular 2: Can't bind to 'ngModel' since it isn't a known property of 'input' angular angular

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


Figured out quick solution, update your @NgModule code like this :

import { NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { FormsModule } from '@angular/forms';import { AppComponent } from './app.component';@NgModule({imports: [ BrowserModule, FormsModule ],declarations: [ AppComponent ],bootstrap: [ AppComponent ]})export class AppModule { }

Source: Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’


In order to make ngModel work when using AppModules (NgModule ), you have to import FormsModule in your AppModule .

Like this:

import { NgModule } from '@angular/core';import { BrowserModule  } from '@angular/platform-browser';import { FormsModule } from '@angular/forms';import { AppComponent }   from './app.component';@NgModule({    declarations: [AppComponent],    imports: [BrowserModule, FormsModule],    bootstrap: [AppComponent]})export class AppModule {}


I encountered a similar error after upgrading to RC5; i.e. Angular 2: Can't bind to 'ngModel' since it isn't a known property of 'input'.

The code on Plunker show you using Angular2 RC4, but the example code at https://angular.io/docs/ts/latest/cookbook/dynamic-form.html is using NGModule which is part of RC5. NGModules is a breaking change from RC4 to RC5.

This page explains the migration from RC4 to RC5: https://angular.io/docs/ts/latest/cookbook/rc4-to-rc5.html

I hope this addresses the error you're getting and help get you going in the right direction.

In short, I had to create an NGModule in app.module.ts:

import { NgModule }      from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { FormsModule }   from '@angular/forms';import { AppComponent }  from './app.component';@NgModule({    imports:      [ BrowserModule, FormsModule ],    declarations: [ AppComponent ],    bootstrap:    [ AppComponent ]})export class AppModule { }

I then changed main.ts to use the module:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';import { AppModule } from './app.module';platformBrowserDynamic().bootstrapModule(AppModule);

Of course, I also needed to update the dependencies in package.json. Here's my dependencies from package.json. Admittedly, I've hobbled them together from other sources (maybe the ng docs examples), so your mileage may vary:

..."dependencies": {    "@angular/common": "2.0.0-rc.5",    "@angular/compiler": "2.0.0-rc.5",    "@angular/core": "2.0.0-rc.5",    "@angular/forms": "0.3.0",    "@angular/http": "2.0.0-rc.5",    "@angular/platform-browser": "2.0.0-rc.5",    "@angular/platform-browser-dynamic": "2.0.0-rc.5",    "@angular/router": "3.0.0-rc.1",    "@angular/router-deprecated": "2.0.0-rc.2",    "@angular/upgrade": "2.0.0-rc.5",    "systemjs": "0.19.27",    "core-js": "^2.4.0",    "reflect-metadata": "^0.1.3",    "rxjs": "5.0.0-beta.6",    "zone.js": "^0.6.12",    "angular2-in-memory-web-api": "0.0.15",    "bootstrap": "^3.3.6"  },...

I hope this helps better. :-)