晚上都。有人可以告诉我如何在加载ng-repeat时设置单选按钮吗?在下表中,我列出了具有创建的排序功能的价格。它从最低价格到最低排序。有什么方法可以将每次加载表格时的最低价格单选按钮设置为“选中”?
<table>
<tr ng-repeat="prices in productVariant.prices | orderBy: tcoSort">
<td><strong>{{prices.code }}</strong></td>
<td ng-click="displayFullPricing(prices)">
<input type="radio" name="{{variant.code}}" ng-click="displayFullPricing(prices, $index)">
</td>
</tr>
$scope.tcoSort = function (productVariant) {
return productVariant.nonRecurring.retailPrice + (productVariant.monthly.retailPrice * $scope.productAttributesObj.Term);
};
谢谢
非常简单地使用$ scope.modelName并将其值设置为您要默认设置的单选按钮的任何值(属性),例如:
男女
现在在控制器中设置$ scope.one =“ male”,您将获得默认值单选按钮。
如果ng-repeat概念相同,但是您只需要在ng-repeat模型中使用$ parent,因为ng-repeat创建了自己的作用域,无法从控制器访问它。
下面是一个小的模拟示例:
<div ng-repeat="check in people">
<input type="radio" name="hello" value="{{check.name}}" ng-model="$parent.human"/> {{check.name}}
</div>
$scope.people=[
{
'name':'rachit'
},
{
'name':'gulati'
},
{
'name':'rocks'
}
]
$scope.human='gulati';//You need to set it to the lowest price from your array .
这是小提琴
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句