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?

Qaz
  • 1,556
  • 2
  • 20
  • 34

1 Answers1

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">
user3227295
  • 2,168
  • 1
  • 11
  • 17