AngularJs:如何设置单选按钮托运基于模型 [英] AngularJs: How to set radio button checked based on model
本文介绍了AngularJs:如何设置单选按钮托运基于模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个模型在storeLocations返回一个ISDEFAULT值对象。如果ISDEFAULT返回true,我wan't设置组中的单选按钮选中。
不知道如果我需要做一个$每次(数据,功能(指数值),并通过每个对象返回迭代,或者如果有一个更简单的方法来做到这一点采用了棱角分明的结构。
对象:
storeLocations = [
{
......更多的价值,
ISDEFAULT:真
}
]
标记:
< TR NG重复=位置merchant.storeLocations>
&所述; TD> {{location.name}}&下; / TD>
&所述; TD> {{location.address.address1}}&下; / TD>
&所述; TD> {{location.address.address2}}&下; / TD>
&所述; TD> {{location.address.city}}&下; / TD>
&所述; TD> {{location.address.stateProvince}}&下; / TD>
< TD> {{location.address.postal code}}< / TD>
&所述; TD> {{location.address.country}}&下; / TD>
&所述; TD> {{location.website}}&下; / TD>
&所述; TD> {{location.zone}}&下; / TD>
< TD><输入类型=电台NG-模式=location.isDefaultVALUE ={{location.isDefault}}NAME =isDefault_group>< / TD>
解决方案
使用 NG-值
而不是值
NG-值=真
与版本NG-检查
更糟糕的是,因为code重复。
I have a model returning in the storeLocations object with a isDefault value. if isDefault returns true, I wan't to set that radio button in the group as checked.
Not sure if I need to do a $each(data, function(index,value) and iterate through each object returned or if there's an easier way to do this using angular constructs.
Object:
storeLocations = [
{
... more values,
isDefault: true
}
]
Markup:
<tr ng-repeat="location in merchant.storeLocations">
<td>{{location.name}}</td>
<td>{{location.address.address1}}</td>
<td>{{location.address.address2}}</td>
<td>{{location.address.city}}</td>
<td>{{location.address.stateProvince}}</td>
<td>{{location.address.postalCode}}</td>
<td>{{location.address.country}}</td>
<td>{{location.website}}</td>
<td>{{location.zone}}</td>
<td><input type="radio" ng-model="location.isDefault" value="{{location.isDefault}}" name="isDefault_group"></td>
解决方案
Use ng-value
instead of value
.
ng-value="true"
Version with ng-checked
is worse because of the code duplication.
这篇关于AngularJs:如何设置单选按钮托运基于模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文