Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
42
rated 0 times [  47] [ 5]  / answers: 1 / hits: 146424  / 12 Years ago, mon, february 11, 2013, 12:00:00

I want to use the index of the parent list (foos) as an argument to a function call in the child list (foos.bars).



I found a post where someone recommends using $parent.$index, but $index is not a property of $parent.



How can I access the index of the parent ng-repeat?



<div ng-repeat=f in foos>
<div>
<div ng-repeat=b in foos.bars>
<a ng-click=addSomething($parent.$index)>Add Something</a>
</div>
</div>
</div>

More From » angularjs

 Answers
27

My example code was correct and the issue was something else in my actual code. Still, I know it was difficult to find examples of this so I'm answering it in case someone else is looking.



<div ng-repeat=f in foos>
<div>
<div ng-repeat=b in foos.bars>
<a ng-click=addSomething($parent.$index)>Add Something</a>
</div>
</div>
</div>

[#80303] Saturday, February 9, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jadyngraysons

Total Points: 455
Total Questions: 109
Total Answers: 98

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
jadyngraysons questions
Thu, Apr 23, 20, 00:00, 4 Years ago
Sat, Jan 18, 20, 00:00, 4 Years ago
Tue, Dec 31, 19, 00:00, 4 Years ago
;