本文介绍了[[ngModel)]和[ngModel]之间的绑定状态与属性之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个模板示例:
<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"
是[ngModel]="overRideRate" (ngModelChange)="overRideRate = $event"
[(ngModel)]="overRideRate"
is the short form of [ngModel]="overRideRate" (ngModelChange)="overRideRate = $event"
-
[ngModel]="overRideRate"
用于将overRideRate
绑定到input.value
-
(ngModelChange)="overRideRate = $event"
用于在发出change
事件时用input.value
的值更新overRideRate
.
[ngModel]="overRideRate"
is to bindoverRideRate
to theinput.value
(ngModelChange)="overRideRate = $event"
is to updateoverRideRate
with the value ofinput.value
when thechange
event was emitted.
它们共同构成了Angular2提供的双向绑定.
Together they are what Angular2 provides for two-way binding.
这篇关于[[ngModel)]和[ngModel]之间的绑定状态与属性之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!