0

Included is an object array being used in an ng-repeat call

enter image description here

And here is the error

enter image description here

For the love of me I cannot seem to get why angular is treating these as duplicates.

Any help is much appreciated.

2
  • Please add your ng-repeat code to this question. Commented Sep 11, 2016 at 2:36
  • Based on that error, it looks like there actually are duplicates, and the data you posted isn't the same as what's in your app, i.e. "title":"Timi Aiyemo" Commented Sep 11, 2016 at 14:52

1 Answer 1

2

Angular is telling you it doesn't know how to differentiate the items in your list, so you must tell it which field in your objects make it unique. Click here for more documentation on track by

To do this you need to add track by to your ng-repeat statement. You can specify any field on the object such as yid.

<div ng-repeat="item in items track by item.yid">
    ...
</div>

However, if you didn't have any fields that tracked uniqueness, you can also track by the index of the item in the list using $index.

<div ng-repeat="item in items track by $index">
    ...
</div>
Sign up to request clarification or add additional context in comments.

2 Comments

Sigh...feared as much. The problem is that theres a feature where users can delete a list item and track by causes the deletion experience for the user to be clunky. Thanks alot.
That seems strange since track by should be virtually transparent. It should just be a matter of removing the item from the list or reloading the list of items. In the case of your yid that should be unique, so it won't matter in either case.

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.