An array instance in an angular ng repeat array
- 2021-07-22 08:27:10
- OfStack
//Define an array first
anular code:
var app = angular.module('serApp', []);
app.controller('indexCtrl', function($scope, $http)
{ $scope.arrs = [{
<BR> n:'a' ;
arr:['1','2','1']
},{<BR><BR> n:'b' ;
arr:['4','5','6']
}];
})
html code:
<BR>
<div ng-controller="indexCtrl"><BR>
<p>{{name}}</p><BR>
<ul><BR>
<li ng-repeat="name in names">{{name.n}}<BR>
<p ng-repeat="a in name.arr track by $index" id="{{$index}}">{{a}}</p><BR>
</li><BR>
</ul>
<BR>
</div><BR><BR>
track by $index Add this code if there is a duplicate value or the browser will report this error Error: [ngRepeat: dupes] and will not render to the page