一切都不顺利。 ng-repeat工作正常。它是从json创建选项,但问题是每个收音机都有相同的名称。因为一次只能选择一个无线电。如何为每个广播组生成唯一的名称扩展名。
这是plnkr。 http://plnkr.co/edit/Vze4y6QEerhiTPX7sEZz?p=preview
var app = angular.module('q', []);
app.controller('aCtrl', function($scope) {
this.sets = set;
});// Fin aCtrl
var set =
[
{
"qus" :"what is your name?",
"option1" : {"ans" : "Alex", "cor":"false"},
"option2" : {"ans" : "Hervy", "cor":"false"},
"option3" : {"ans" : "Rico", "cor":"true"},
"option4" : {"ans" : "Tom", "cor":"false"},
},
{
"qus" :"what is your brother's name?",
"option1" : {"ans" : "Alex", "cor":"false"},
"option2" : {"ans" : "Hervy", "cor":"true"},
"option3" : {"ans" : "Rico", "cor":"false"},
"option4" : {"ans" : "Tom", "cor":"false"},
},
]
答案 0 :(得分:1)
您可以生成包含迭代索引的名称。例如:
<li class="list-group-item">
<input type="radio" name="op + {{$index}}" ng-value="{{qs.option2.cor}}" ng-model="nv1">
<span class="up">{{qs.option1.ans}}</span>
</li>
因此,群组名称将为op0
,op1
等。