How To Fix Duplicates In A Repeater Are Not Allowed In AngularJS




Here we consider how to fix Duplicates In A Repeater Are Not Allowed Issue. In AngularJs, we use ng-repeater for implementing loops. How to use ng-repeater is explained on the following link.

How To Implement Loops Using Ng-Repeat In AngularJS

But AngularJS does not allow duplicates in a ng-repeat directive. That means, ng-repeat cannot include following type of array. ng-repeat="row in [2,2,2]"

The uniqueness is missing on the above array which will leads to the error.
Here we explain how to resolve this issue.




For resolving this Issue, we have to provide the uniqueness to each array member. This can be achieved by including following line on ng-repeat.
ng-repeat="row in [2,2,2] track by $index"

Duplicates In A Repeater Are Not Allowed In AngularJS, How To Fix Duplicates In A Repeater Are Not Allowed In AngularJS, Duplicates In A Repeater, ng-repeat Duplicates In A Repeater Are Not Allowed In AngularJS, AngularJS, HTML, PHP, Asp.Net

track by $index will provide the uniqueness to each array member. This would give a key for each array member that would optimize the performance.
By this way we can resolve this issue.