, , ng-repeat .
, , .
.
HTML
<body ng-app="myApp" ng-controller="MainCtrl as ctrl">
<ul ng-repeat-start="chunk in ctrl.chunkList">
<li ng-repeat="item in chunk">{{item}}</li>
</ul>
<hr ng-repeat-end/>
</body>
JS
angular
.module('myApp', [])
.controller('MainCtrl', [function() {
var self = this;
var listLength;
var groupNum;
var i;
self.list = [
'item1', 'item2', 'item3', 'item4', 'item5',
'item6', 'item7', 'item8'
];
listLength = self.list.length;
groupNum = (listLength % 4 === 0)? listLength / 4 : Math.ceil(listLength / 4);
self.chunkList = [];
for (i = 0; i < groupNum; i++) {
self.chunkList[i] = self.list.slice(i * 4, (i + 1) * 4);
}
}]);
Also note that if you do not need other elements of the cycle, you can just delete ng-repeat-startand ng-repeat-endinstead to use it ng-repeat.
<body ng-app="myApp" ng-controller="MainCtrl as ctrl">
<ul ng-repeat="chunk in ctrl.chunkList">
<li ng-repeat="item in chunk">{{item}}</li>
</ul>
</body>
Notes
This approach is similar to @Shivas Jayram , but without a library underscore.
source
share