1

The following Angular code displays four dancing hamsters:

<img src="images/dancingHamster.gif" ng-repeat="i in [1,2,3,4]">

whereas this code displays nothing:

<img src="images/dancingHamster.gif" ng-repeat="i in [1,1,1,1]">

Here are some more arrays that work:

[4,3,2,1] ['a','c','b','z']

And here are some that display nothing:

[4,3,2,4] ['a','c','b','a']

As far as I can tell, it only works if there are no repeated elements. Why is this?

1

1 Answer 1

4

if items in array is duplicat use track by $index

<img src="images/dancingHamster.gif" ng-repeat="i in [1,1,1,1] track by $index">
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.