Access index of the parent ng-repeat from child ng-repeat

后端 未结 6 706
不思量自难忘°
不思量自难忘° 2020-11-28 19:43

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 $par

6条回答
  •  野性不改
    2020-11-28 20:16

    According to ng-repeat docs http://docs.angularjs.org/api/ng.directive:ngRepeat, you can store the key or array index in the variable of your choice. (indexVar, valueVar) in values

    so you can write

    
    

    One level up is still quite clean with $parent.$index but several parents up, things can get messy.

    Note: $index will continue to be defined at each scope, it is not replaced by fIndex.

提交回复
热议问题