做问卷调查功能项目时,使用了ng-repeat 里面嵌套 ng-repeat 然后获取radio的ng-model值时,发现只能获取到当前点到的radio的值;而点击checkbox的时候,angular报错 Error: [$rootScope:infdig],代码如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32html结构:
<ul class="options_box" >
<li ng-repeat="item in ques" >
<div class="opt" ng-repeat="nums in item.ques_item_options track by $index">
<!-- 单选 -->
<input type="radio" class="magic-radio " name="{{nums.ques_item_option}}"
value="{{item.ques_item_id}},{{nums.item_option_id}}"
id="{{nums.item_option_id}}"
title="{{nums.ques_item_option}}"
ng-model="formdata.option_id[$index]"
ng-if="item.ques_item_type==1" ng-required="required"
/>
<!-- 多选 -->
<input class="magic-checkbox" type="checkbox" name="{{nums.ques_item_option}}"
id="{{nums.item_option_id}}"
ng-model="formdata.item_option_id[$index]"
ng-true-value="'{{item.ques_item_id}},{{nums.item_option_id}}'"
ng-false-value="'NO'"
ng-checked="formdata.item_option_id[$index]"
ng-if="item.ques_item_type==2"
ng-checked="nums.selected"
ng-required="formdata.item_option_id[$index]"
/>
<label for="{{nums.item_option_id}}">
<p class="right">
<i ng-bind="nums.item_option_id"></i>
<i ng-bind="nums.ques_item_option"></i>
</p>
</label>
</div>
</li>
</ul>
如何取到第二级嵌套的ng-model的?
只需要在第几层的ng-model上加上相应级数的$parent,然后后面加上model的定义值即可