4
votes

I have been experimenting with one-way and two-way binding to an input element using ngModel.

I wish to bind from view to model, in order to capture user input. I can accomplish this by creating a variable, for e.g. someVar, in a Component, and binding to it in the corresponding view template using [(ngModel)]="someVar".

I understand that this is syntactic sugar for [ngModel]="someVar" and (ngModelChange)="someVar=$event".

However, if i omit the model to view binding, namely [ngModel]="someVar", then the value of someVar remains undefined.

I cannot understand this behaviour, since omitting the view to model binding does not cause any problems.

1
Is your question why it behaves this way or how to get a binding from the view to the model without the other way around? - Ingo Bürk

1 Answers

5
votes

[ngModel] is required to use (ngModelChange) because it is the @Output of ngModel directive.