English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
//Prima di tutto, definire un array
Codice Angular:
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'] }; )
Codice HTML:
<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 deve essere aggiunto quando ci sono valori duplicati, altrimenti il browser genererà questo errore Error: [ngRepeat:dupes] e non renderà il contenuto nella pagina
Questa guida su angular ng-repeat array è tutto ciò che ho condiviso con voi, spero che possa essere un riferimento utile e che possiate sostenere Tutorial di urla.