Let's say I have 8 items in my array. While looping through this array, I would want to split them into 3 items/page which would give me 3 pages.
The logic is clear but I don't know how one can achieve this using ng-repeat
. If there is no direct way, I'm also open to indirect ways.
In essence, I would like to do something like this:
JS
$scope.items = ["A", "B", "C", "D", "E", "F", "G", "H"];
$scope.pages = Math.ceil($scope.items.length/3);
HTML
<div class="box">
<div class="items" ng-repeat="page in pages">
<!-- put 3 items here and then create a new ".items" div with the next 3 items and so on -->
</div>
</div>
Expected Output
<div class="box">
<div class="items">
<p>A</p>
<p>B</p>
<p>C</p>
</div>
<div class="items">
<p>D</p>
<p>E</p>
<p>F</p>
</div>
<div class="items">
<p>G</p>
<p>H</p>
</div>
</div>