English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Angular ng-Repeat Array of Array Instances

//First define an array

Angular 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 needs to be added when there are duplicate values, otherwise the browser will report this error: Error: [ngRepeat:dupes] and it will not be rendered on the page

The above article angular ng-The instance of array in repeat is all the content that the editor shares with everyone, hoping to provide a reference for everyone, and also hope that everyone will support the呐喊 tutorial more.

You May Also Like