think123 think123 - 1 month ago 6
AngularJS Question

Duplicates in a repeater are not allowed, index already specified

I'm having an issue with AngularJS repeaters:

<table class="data_table" style="margin: 0 5px; width: calc(100% - 10px);">
<tr>
<th>Activity</th>
<th ng-repeat="date in activitiesRangeInfo.labels">{{date | date: 'd/MM'}}</th>
</tr>
<tr ng-repeat="activity in activitiesRangeInfo.generated_datasets track by $index">
<th>{{activitiesRangeInfo.all_activities[$index]}}</th>
<td align="center" ng-repeat="inner in activitiesRangeInfo.generated_datasets[$index] track by $index">
{{inner | number: 1}}
</td>
</tr>
</table>


and this data set:

$scope.activitiesRangeInfo = {
all_activities: ["Tennis"],
generated_datasets: [[0, 0, 420, 0]],
labels: JSON.parse('["2016-10-22T13:00:00.000Z","2016-10-23T13:00:00.000Z","2016-10-24T13:00:00.000Z","2016-10-25T13:00:00.000Z"]')
}


and this error:

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


Please have a look and advise as to what's wrong.

Answer

$indexb isn't valid because it is an Angular defined property. Just use $index. If you want to define your own see this: https://docs.angularjs.org/api/ng/directive/ngInit