Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allow duplicates in ng-repeat?

I am using stringify and json is getting formatted and in alert it is coming.But in actual link it is not displaying. When I checked in console error was coming as "duplicates are not allowed in ng-repeat for the key".

Can anyone tell how to allow duplicates in ng-repeat so that formatted json will be printed.

like image 608
Monali Pradhan Avatar asked Jul 29 '15 18:07

Monali Pradhan


People also ask

How do you prevent duplicates in NG-repeat?

You can use unique filter while using ng-repeat . If you use track by $index then unique won't work.

What can I use instead of NG-repeat?

You can consider using transclusion inside a custom directive, to achieve the behavior you are looking for without using ng-repeat.

What does ng-repeat do?

Definition and Usage. The ng-repeat directive repeats a set of HTML, a given number of times. The set of HTML will be repeated once per item in a collection. The collection must be an array or an object. Note: Each instance of the repetition is given its own scope, which consist of the current item.

How do I get an index in NG-repeat?

Note: The $index variable is used to get the Index of the Row created by ng-repeat directive. Each row of the HTML Table consists of a Button which has been assigned ng-click directive. The $index variable is passed as parameter to the GetRowIndex function.


1 Answers

Add 'track by $index' to the repeater.

https://docs.angularjs.org/error/ngRepeat/dupes

like image 184
The Head Rush Avatar answered Oct 12 '22 18:10

The Head Rush