Shift N' Tab Shift N' Tab -4 years ago 116
AngularJS Question

How to get the parent $index of a nested ng-repeat

anyone knows how to get the first level

$index
of a nested
ng-repeat
?

Here is my data:

vm.rooms = [
{
name: 'Room1', students: ['Cal', 'Ryan', 'Luigi', 'Joel']
},
{
name: 'Room2', students: ['Jaime', 'Sherwin', 'Gami', 'Beau']
},
{
name: 'Room3', students: ['Roel', 'Edwin', 'Carl', 'Necho']
}
]


And i want to get this output:

Room1 - Idx: 0
Cal - Idx: 0 on room idx: 0
Ryan - Idx: 1 on room idx: 0
Luigi - Idx: 2 on room idx: 0
Joel - Idx: 3 on room idx: 0
Room2 - Idx: 1
Jaime - Idx: 0 on room idx: 1
Sherwin - Idx: 1 on room idx: 1
Gami - Idx: 2 on room idx: 1
Beau - Idx: 3 on room idx: 1
Room3 - Idx: 2
Roel - Idx: 0 on room idx: 2
Edwin - Idx: 1 on room idx: 2
Carl - Idx: 2 on room idx: 2
Necho - Idx: 3 on room idx: 2


But i get this one here in my DEMO you can check the html structure there.

Answer Source

You can use $parent to access to scope of the parent. So use

$parent.$index
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download