Angular2: Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
While upgrading your Angular2 code from RC4 to RC5, you may face problem like this “Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’” while using two way binding [(ngModel)]. After researching about new RC5 update I have found the solution for it.
Let’s assume, your old app.module.ts may look similar to this :
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Now, it is the time to update the code according to RC5 update of angular2, you just have to import FormsModule in your app.module.ts & your issue will get resolved. Let’s see how the updated code will look like:
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 { }
After making these required changes, you will be able to use your two way binding without any issue just like you did in RC4. Thanks to Google groups & Angular.io for this solutions.
You can post your queries in comment box below & I will try to help you with my best efforts. Thanks for reading.