I have an array of 6 elements (this is an example of elements can be any number), by which I want to do ng-repeat. But I want two elements to fit into the block. The output should be such

<div class="row"> <div class="col">1 элСмСнт массива</div> <div class="col">2 элСмСнт массива</div> </div> <div class="row"> <div class="col">3 элСмСнт массива</div> <div class="col">4 элСмСнт массива</div> </div> <div class="row"> <div class="col">5 элСмСнт массива</div> <div class="col">6 элСмСнт массива</div> </div> 

    2 answers 2

    use range

    js:

     var myApp = angular.module('myApp', []); myApp.filter('range', function() { return function(input, total) { total = parseInt(total); for (var i=0; i<total; i++) { input.push(i); } return input; }; }); 

    html:

      <tr data-ng-repeat="key in [] | range: items.length/2"> <td>{{items[key]}}</td> <td>{{items[key+1]}}</td> </tr> 

    and you will be happy!

      Just write your directive.

      Or your filter and put the second ng-repeat inside the first.

      • No, you need exactly two col in one row. Well, yes, either confuse with the directive - drm
      • @drm, then you need your own directive. Or your filter and two ng-repeat nested. - Qwertiy ♦