时间:2021-02-02 10:09:40 | 栏目:AngularJS | 点击:次
//先定义一个数组
anular代码:
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 代码:
<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 在有重复值时需加上这段代码 不然浏览器会报这个错 Error: [ngRepeat:dupes]并且不会渲染到页面