• Mother: {{pa...">

    Ng-show for a specific item in ng-repeat

    It seems I can not solve this little problem:

    <ul ng-repeat="parent in parents">
      <li>Mother: <i>{{parent.mother}}</i></li>
      <li>Father: <i>{{parent.father}}</i></li>
      <a href="#" ng-click="showKids()">Show Kids</a>
      <ul ng-repeat="kid in parent.kids" ng-show="active">
        <li>{{kid.name}}</li>
      </ul>
    </ul>
    

    http://jsfiddle.net/twSFK/5/

    When I click Show Children, I want to show my parents where I clicked, but not the other. Therefore, I need some kind of index for the model that I use in ng-show, in order to target only a specific element.

    Since $ scope.parents comes from the backend server and is loaded using ng-init, I don’t know how I can access it to add an “active” element before the controller writes the list.

    +5
    source share
    1 answer

    ng-repeat="parent in parents" : showKids(index) , , , isShowing(index), , , ng-show

    http://jsfiddle.net/odiseo/twSFK/7/

    +10

    All Articles