How to divide data to half while using ng-repeat? How to divide data to half while using ng-repeat? angularjs angularjs

How to divide data to half while using ng-repeat?


There is even a cleaner and simpler solution, but you must use angular 1.2.1: https://jsfiddle.net/1fch1221/6/

<div ng-controller="Ctrl"><div class="left">  <div ng-repeat="item in data" ng-if="$index < (data.length / 2)">{{item.value}}</div></div><div class="right">  <div ng-repeat="item in data" ng-if="$index >= (data.length / 2)">{{item.value}}</div></div>


You can use two variables, like so

function Ctrl($scope) {  $scope.data = [      {value: "a"},      {value: "b"},      {value: "c"},      {value: "d"},// trying to divide from here      {value: "e"},// and show the last part in other column      {value: "f"},      {value: "g"},      {value: "h"}  ];  var len = $scope.data.length,      mid = len / 2;  $scope.left  = $scope.data.slice(0, mid);    $scope.right = $scope.data.slice(mid, len);}

Example


I don't know is it cleaner than the other answers, but as idea:

ng-repeat="item in data.slice(0, data.length / 2)"ng-repeat="item in data.slice(data.length / 2, data.length)"