title: AngularJS: Ng-repeat in groups of n elements
body: <p>I have a set of data like this:</p>
  
  <pre><code>$scope.items = [
      { model:"A", price: 100, quantity: 30}, 
      { model:"B", price: 90, quantity: 20 },
      { model:"C", price: 80, quantity: 200 }, 
      { model:"D", price: 70, quantity: 20 },
      { model:"E", price: 60, quantity: 100 }, 
      { model:"F", price: 50, quantity: 70 },
      { model:"G", price: 40, quantity: 230 }, 
      { model:"H", price: 30, quantity: 50 }
  ];
  </code></pre>
  
  <p>I would like use ng-repeat but then making groups of 4, so the output would be something like this</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li&gt; model:"A", price: 100, quantity: 30&lt;/li&gt;
      &lt;li&gt; model:"B", price: 90, quantity: 20&lt;/li&gt;
      &lt;li&gt; model:"C", price: 80, quantity: 200&lt;/li&gt;
      &lt;li&gt; model:"D", price: 70, quantity: 20&lt;/li&gt;
  &lt;/ul&gt;
  &lt;ul&gt;
      &lt;li&gt; model:"E", price: 60, quantity: 100&lt;/li&gt;
      &lt;li&gt; model:"F", price: 50, quantity: 70&lt;/li&gt;
      &lt;li&gt; model:"G", price: 40, quantity: 230&lt;/li&gt;
      &lt;li&gt; model:"H", price: 30, quantity: 50&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>And then be able to sort it by price and quantity. I've tried with </p>
  
  <pre><code>&lt;li ng-repeat="x in items.slice(0,4)"&gt;
  </code></pre>
  
  <p>but then I just can sort within each group. Also, I am looking for a solution that could work for any given number of elements. This proposed solution <a href="https://stackoverflow.com/questions/19285351/group-ng-repeat-items">Group ng-repeat items</a> just work when you know in advance the number of items that you will have.</p>
  
  <p>PS: I'm trying not to use the pagination directive as it gives me a conflict with other script.</p>
  
  <p>Thanks in advance!</p>