参见jsBin
对于数组中的每一项,我尝试创建一个包含 6 个单选按钮的列表,其中第四项最初是所有单选按钮中的选中值。然而,当渲染时,仅检查最后一组单选按钮的第四项。 name="checkpoint{{$index}}"
正在工作,因为组可以单独选择,只是值的初始设置不能。
<table>
<tbody>
<tr ng-repeat="checkpoint in checkpoints">
<td>
<input type="radio" name="checkpoint{{$index}}" />
<input type="radio" name="checkpoint{{$index}}" />
<input type="radio" name="checkpoint{{$index}}" />
<input type="radio" name="checkpoint{{$index}}" checked /> <!-- This checked property is only working on the last set of radio buttons -->
<input type="radio" name="checkpoint{{$index}}" />
<input type="radio" name="checkpoint{{$index}}" />
checkpoint{{$index}}
</td>
</tr>
</tbody>
</table>
以及相应的 JavaScript:
var app = angular.module('app', []).controller('MyController', function($scope) {
$scope.checkpoints = [
{
name: "one"
},
{
name: "two"
},
{
name: "three"
},
{
name: "four"
}
];
});
最佳答案
尝试使用
ng-checked="true"
而不是 native 检查
。
编辑: ngChecked 的文档供引用。 https://docs.angularjs.org/api/ng/directive/ngChecked
关于javascript - ng-repeat 具有 "checked"属性的多个单选按钮组——仅检查最后一个组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24745411/