简体   繁体   中英

Nested Loops (ng-repeat) in AngularJS with $index

Lets say we have two ng-repeat (nested) in angularJS:

<div ng-repeat="animal of animals track by $index">
    <div ng-repeat="name in names">
        <p>{{$index}}</p>
    </div>
</div>

In this example the $index would be the index of the child loop in names, but i want to have the index of the parent loop animals where i have the track by.

Why is this not working?

Try this.

  <div ng-repeat="animal of animals track by $index">
        <div ng-repeat="name in names">
            <p>{{$parent.$index}}</p>
        </div>
    </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM