从范围的角度JS NG-重复一个单选按钮列表用默认选中 [英] angular js ng-repeat a radio button list from scope with a default checked
本文介绍了从范围的角度JS NG-重复一个单选按钮列表用默认选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
app.controller('radiusController', function($scope){
$scope.radii = [
{id:.25, checked:"false", name:"1/4 Mile"},
{id:.5, checked:"false", name:"1/2 Mile"},
{id:1, checked:"false", name:"1 Mile"},
{id:2, checked:"true", name:"2 Mile"},
{id:3, checked:"false", name:"3 Mile"},
{id:4, checked:"false", name:"4 Mile"},
{id:5, checked:"false", name:"5 Mile"}
];
$scope.handleRadioClick = function(radius){
window.radiochecked = radius.id;
};
});
<li ng-repeat="radius in radii" id="selectradius-{{radius.id}}">
<div class="radio">
<label>
<input type="radio" name="radius"
ng-model="radius.checked"
ng-change="handleRadioClick(radius)">
{{radius.name}}
</label>
</div>
</li>
我如何设置默认的单选按钮,可以根据半径范围内的检查值检查?在这种情况下,2英里应该是默认进行检查。
How do I set the default radio button to be checked based on the checked value of scope radii? In this case the "2 Mile" should be checked by default.
plunker: http://plnkr.co/edit/RP9SpO1qGjn5Ua6pZJ3D?p=preVIEW
推荐答案
简单。 Eventhough角文档不提NG-检查,它是可用的。
Simple. Eventhough the angular docs do not mention ng-checked, it is available.
<input type="radio" name="radius"
ng-change="handleRadioClick(radius)"
ng-checked="radius.checked">
这篇关于从范围的角度JS NG-重复一个单选按钮列表用默认选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文