search

Home  >  Q&A  >  body text

angular.js - How to get the value of ng-model when using ng-if and ng-repeat on a parent-child element at the same time?

I use ng-if on a ul, then use ng-repeat on li, and then use ng-model on the specific elements inside. How can I get this model value? It is already in ng-model. I used $parent, but still can’t get the value. The code is as follows:

<ul ng-if="datas.vote_choose_type==2">
    <li class="opt" 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"
                class="magic " 
                name="quan1" 
                value="{{num.option_id}}" 
                id="{{num.option_id}}" 
                title="{{num.option}}" 
                ng-model="$parent.option_id"  
                ng-checked="$parent.option_id"  
                ng-class="{'magic-radio':datas.vote_choose_type==1,'magic-checkbox':datas.vote_choose_type==2}" />
        <label for="{{num.option_id}}">{{num.option}}</label>
   </li>
</ul>

I have tried to use ng-show, but it will affect a specific parameter value obtained from the server. Could you please help me explain, is it because of the scope? Or is there some other reason? Is there any good way to solve this problem? Thank you! ! !

过去多啦不再A梦过去多啦不再A梦2842 days ago854

reply all(1)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-27 17:46:31

    Because of the sub-scope, you only need to add $parent.$parent. Your two-way data binding name to the ng-model in the ng-repeat under ng-if. It has been tested and has not been found yet. other problems.

    reply
    0
  • Cancelreply