Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS Nested ng-repeat Not Working in Version 1.2.1

I am working on a system where I would like to nest two ng-repeat statements so that I can work my way through a 2D array. I was able to complete the task successfully using version 1.1.1 as you can see here:

http://jsfiddle.net/skArT/1/

However, when I take the exact same code set and change the version of Angular to 1.2.1 the code no longer works and throws an error:

http://jsfiddle.net/skArT/2/

Error:

Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: x in value, Duplicate key: number:0

So my question is, how can I accomplish the task shown in version 1.1.1 with newer versions of Angular?

like image 607
Shane Avatar asked Dec 13 '25 12:12

Shane


1 Answers

All you need to do is read the error message and listen to it. Change:

<div ng-repeat="x in value">{{x}}</div>

To:

<div ng-repeat="x in value track by $index">{{x}}</div>
like image 129
Justin Niessner Avatar answered Dec 16 '25 10:12

Justin Niessner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!