是什么value`属性和`在angularjs NG-value`属性之间`的区别 [英] What is the difference between `value` attribute and `ng-value` attributes in angularjs
问题描述
什么是值
和 NG-值
在angularjs模板属性之间的区别?如果我用值中使用 NG-IF
场上属性它工作正常,但如果我更改属性值
到 NG-值
将停止工作。
例如1 //它的工作原理<输入类型='无线电'NG-模式='困难'值='硬'/>
< DIV NG-IF =难度=='硬'>
&所述p为H.;困难是硬下; / P>
< / DIV>例2 //这是行不通的<输入类型='无线电'NG-模式='级别'NG值='硬'/>
< DIV NG-IF =级=='硬'>
&所述; P>级是硬下; / P>
< / DIV>
据 的文档一> , ngValue
需要一个的角前pression,其价值将被绑定到值
的输入
元素的属性的
所以,当你使用 NG-值=硬
,这是PTED作为一个前pression和值
势必 $ scope.hard
(这可能是未定义
)< BR> ngValue
是评估前pressions有用 - 它没有优势值
设置硬codeD值。然而,如果你想用硬 ngValue
codeA值,则必须将其括在:
NG-值='硬'
What is the difference between value
and ng-value
attributes in angularjs templates? If I use ng-if
on the field using value attribute it works properly but if I change the attribute value
to ng-value
it stops working.
example 1 // it works
<input type='radio' ng-model='difficulty' value='hard'/>
<div ng-if="difficulty == 'hard'">
<p>difficulty is hard</p>
</div>
Example 2 // it doesn't work
<input type='radio' ng-model='level' ng-value='hard'/>
<div ng-if= "level == 'hard'" >
<p>level is hard</p>
</div>
According to the docs, ngValue
takes an "angular expression, whose value will be bound to the value
attribute of the input
element".
So, when you use ng-value="hard"
, it is interpreted as an expression and the value
is bound to $scope.hard
(which is probably undefined
).
ngValue
is useful for evaluating expressions - it has no advantage over value
for setting hard-coded values. Yet, if you want to hard-code a value with ngValue
, you must enclose it in ''
:
ng-value="'hard'"
这篇关于是什么value`属性和`在angularjs NG-value`属性之间`的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!