I ran into a issue using Angular 2 ngModel binding. plnkr
If I use ngModel to bind a value to a child component, the value is not populated on the OnInit function of the child component. So If I bind to a property call "boundName" and I try to access that in the OnInit, it will be null. However if I bind the to the same value in the parent control not using ngModel but a input parameter, the value is accessible in the OnInit function.
So.. if my parent component creates a child component like
<my-boundcomp [(ngModel)]="name" [(inputName)] ="name" ></my-boundcomp>
And my child components onInit Function is
public ngOnInit() {
console.log("Input Name :" + this.inputName);
console.log("Bound Name :" + this.boundName);
this._boundNameOnInit = this.boundName; // <--- Going to be null
this._inputNameOnInit = this.inputName; // <--- Going to be not null
}
I found this behavior to be odd, and unexpected. I'm not sure if this is a bug or I am not using the FormsModule ngModel correctly, but interesting enough that I thought I should share.
Here is the full plnkr https://plnkr.co/edit/Im5oz7q1HhG5MgGTTZ1R?p=preview