问题描述
在一个ul上面使用了ng-if,然后在li上面使用了ng-repeat,再然后里面具体上面的元素上使用了ng-model,请问怎么取到这个model值,已经在ng-model上使用了$parent,但是还是取不到值,代码如下:
<ul ng-if='datas.vote_choose_type==2'> <li ng-repeat='num in datas.vote_options track by $index' ng-class='{’finished’:num.is_voted == 1,’1’:num.is_voted == 2}'><input type='radio' name='quan1' value='{{num.option_id}}' ng-model='$parent.option_id' ng-checked='$parent.option_id' ng- /><label for='{{num.option_id}}'>{{num.option}}</label> </li></ul>
已经尝试过使用ng-show,但是会影响从服务端获取的具体的某个参数值,请问各位路过的大神们,帮忙解释一下,是因为作用域的原因吗?还是其他什么原因,有什么好的方法可以解决这个问题,跪谢!!!
问题解答
回答1:因为子作用域的原因,只需要在ng-if下面的ng-repeat里面的ng-model上加一个$parent.$parent.你的双向数据绑定名称即可,已经测试过,暂未发现其他问题。