Here is a template example:
<input type="number" class="form-control" [(ngModel)]="overRideRate" formControlName="OverRideRate">
<input type="number" class="form-control" [ngModel]="overRideRate" formControlName="OverRideRate">
Here both of them do the same thing. Which one is preferred and why?
[(ngModel)]="overRideRate"
is the short form of [ngModel]="overRideRate"
(ngModelChange)="overRideRate = $event"
[ngModel]="overRideRate"
is to bind overRideRate
to the input.value
(ngModelChange)="overRideRate = $event"
is to update overRideRate
with the value of input.value
when the change
event was emitted.Together they are what Angular2 provides for two-way binding.