0

I have an array with items for which I don't know neither keys or values. Looks like this:

{"key1":true,"key2":true, "key3":'value'}

If I loop using ng-repeat: ng-repeat="(k, v) in array" I get Duplicates in a repeater are not allowed.

How can I loop this kind of array in angular template, where I don't know neither the keys, values or it's length?

m59
  • 43,214
  • 14
  • 119
  • 136
Alexandru R
  • 8,560
  • 16
  • 64
  • 98
  • 3
    That is not an array, that is an object. – Adrian Marinica Sep 04 '13 at 14:33
  • possible duplicate of [Error "Duplicates in a repeater are not allowed." when using cutom filter in angular.js](http://stackoverflow.com/questions/16296670/error-duplicates-in-a-repeater-are-not-allowed-when-using-cutom-filter-in-ang) – m59 Sep 04 '13 at 14:52

1 Answers1

7

This ought to fix it! ng-repeat="(k, v) in myObj track by $index"

Something internal with angular has to keep up with each item to track changes, and it is identifying each one by the value. When it finds a duplicate, it can't track that way without issues, so it throws the error. This is changing the way it tracks the changes, so it may have a side-effect. I haven't seen any issue arise from tracking by index, but keep an eye on it to be sure.

Oh, and that isn't array, as one of the comments pointed out =D

m59
  • 43,214
  • 14
  • 119
  • 136