0

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?

1 Answer 1

1

Try this.

  <div ng-repeat="animal of animals track by $index">
        <div ng-repeat="name in names">
            <p>{{$parent.$index}}</p>
        </div>
    </div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.