Difference between [(ngModel)] and [ngModel] for binding state to property?
[(ngModel)]="overRideRate"
is the short form of [ngModel]="overRideRate" (ngModelChange)="overRideRate = $event"
[ngModel]="overRideRate"
is to bindoverRideRate
to theinput.value
(ngModelChange)="overRideRate = $event"
is to updateoverRideRate
with the value ofinput.value
when thechange
event was emitted.
Together they are what Angular2 provides for two-way binding.
[ngModel]="currentHero.name"
is the syntax for one-way binding, while,
[(ngModel)]="currentHero.name"
is for two-way binding, and the syntax is compound from:
[ngModel]="currentHero.name"
and (ngModelChange)="currentHero.name = $event"
If you only need to pass model, use the first one. If your model needs to listen change events (e.g. when input field value changes), use the second one.
It's quite simple [] => component to template() => template to component [(ngModel)]
is a contracted form of [ngModel]="currentHero.name" (ngModelChange)="currentHero.name=$event">
More detail here :https://angular.io/docs/ts/latest/guide/template-syntax.html#!#ngModel