WhoAmI
WhoAmI

Reputation: 317

ng-repeat value in array with same name

In my array there is multiple key value having same name . I want to list them all in my View how can I achieve that ?

I am facing error stating [ngRepeat:dupes] Duplicates in a repeater are not allowed.

This is my JSON array :-

["text-align", "space-before", "space-before.conditionality", "font-size", "font-weight", "line-height", "font-size", "font-weight", "line-height", "space-before", "font-size", "font-weight", "line-height", "position", "top", "bottom", "right", "left", "text-align", "force-page-count", "break-before", "font-size"]

As we can see few keys are repeating . I need to list all repeated values without missing any in my View

Upvotes: 0

Views: 407

Answers (2)

Ankit Agarwal
Ankit Agarwal

Reputation: 30739

You you use ng-repeat it loops over the unique values in the array. If you have duplicate values then you need to explicitly mention the Angular module to ignore the values to be unique and look for unique index value, by doing:

ng-repeat = "item in items track by $index"

Using track by you can explicitly mention that which value should be checked as a uniqueness measure while rendering the DOM using ng-repeat. You can even use the property of the object like item in items track by item.id where item is a object having id property and items is a array of objects.

Your array has font-size specified multiple times in the array so use track by $index.

Upvotes: 1

Nishant Dixit
Nishant Dixit

Reputation: 5522

You can use track by $index to remove this error, something like this

<tag ng-repeat="item in items  track by $index">

//content

</tag>

https://docs.angularjs.org/api/ng/directive/ngRepeat

Upvotes: 1

Related Questions