我正在尝试在选中按钮时获取单选按钮的值。 正如您所看到的,它在ng-repeat范围的第一个工作正常
<div ng-controller="myController as vm">
<ul>
<li ng-repeat="c in vm.questionbox">
<label for="ques{{$index}}"><input ng-model="$parent.mode" type="radio" name="question" id="ques{{$index}}" ng-value="{{c.value}}"> {{c.name}}</label>
<ul ng-show="mode == c.value">
<li ng-repeat="(key, value) in c.answers">
<label for="ans{{c.id}}{{$index+1}}"><input ng-model="$parent.result.value" value="{{value}}" type="radio" name="answer{{c.id}}" id="ans{{c.id}}{{$index+1}}"> {{value}}</label>
</li>
</ul>
<div>currently selected: {{result.value}}</div>
</li>
</ul>
<div>currently selected: {{result.value}}</div>
</div>
但是我也想在ul标签之后得到这个值(在vm.questionbox中的ng-repeat =“c之外”)。请一些解决方案。
您可以在此链接中查看完整代码:http://plnkr.co/edit/Ovwh4M2COIuqDXaQVU5X?p=preview
答案 0 :(得分:0)
答案 1 :(得分:0)
将每个单选按钮的结果保存在列表中。
<li ng-repeat="(key, value) in c.answers">
<label for="ans{{c.id}}{{$index+1}}"><input ng-model="c.selectedAnswer" value="{{value}}" type="radio" name="answer{{c.id}}" id="ans{{c.id}}{{$index+1}}"> {{value}}</label>
</li>
使用简单的ng-repeat
打印所选结果<div>currently selected: <div ng-repeat="answer in vm.questionbox">{{answer.selectedAnswer}} </div></div>