本文介绍了`[[(ngModel)]`vs`[[value)]`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
两者之间有什么区别
<input [(ngModel)]="name">
和
<input [(value)]="name">
他们似乎在做同样的事情.
They appear to do the same thing.
Angular文档使用的是 NgModel ,但他们还说他们用盒装香蕉" [()]替换了所有angular1指令.那么为什么 NgModel 仍然存在?
The angular docs are using NgModel but they also say that they replace all the angular1 directives with the "boxed banana" [()]. So why is NgModel still around?
我想念什么?
推荐答案
-
ngModel
是一条指令,允许您的输入参与表单(但也可以在没有表单的情况下使用) -
value
是一个属性,您可以使用[value]="name"
将值绑定到该属性,而(valueChange)="..."
不起作用,因为<input>
元素没有@Output() valueChange;
,因此[(value)]="..."
无效./li>ngModel
is a directive that allows your input to participate in a form (but works also without a form)value
is a property you can bind a value to with[value]="name"
while(valueChange)="..."
doesn't work, because the<input>
element doesn't have an@Output() valueChange;
therefore[(value)]="..."
is invalid.
[(ngModel)]="name"
是[ngModel]="name" (ngModelChange)="name = $event"
的简写,[(value)]="name"
是[value]="name" (valueChange)="name = $event"
这篇关于`[[(ngModel)]`vs`[[value)]`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!