0
votes

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?

1
That is not an array, that is an object.Adrian Marinica

1 Answers

7
votes

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