title: angular grouping filter
body: <p>Following <a href="https://stackoverflow.com/questions/14123307/angular-js-conditional-markup-in-ng-repeat">angular.js conditional markup in ng-repeat</a>, I tried to author a custom filter that does grouping. I hit problems regarding object identity and the model being watched for changes, but thought I finally nailed it, as no errors popped in the console anymore.</p>
  
  <p>Turns out I was wrong, because now when I try to combine it with other filters (for pagination) like so</p>
  
  <pre><code>&lt;div ng-repeat="r in blueprints | orderBy:sortPty | startFrom:currentPage*pageSize | limitTo:pageSize | group:3"&gt;
        &lt;div ng-repeat="b in r"&gt;
  </code></pre>
  
  <p>I get the dreaded "10 $digest() iterations reached. Aborting!" error message again.</p>
  
  <p>Here is my group filter: </p>
  
  <pre><code>filter('group', function() {
    return function(input, size) {
      if (input.grouped === true) {
        return input;
      }
    var result=[];
    var temp = [];
    for (var i = 0 ; i &lt; input.length ; i++) {
        temp.push(input[i]);
        if (i % size === 2) {
            result.push(temp);
            temp = [];
        }
    }
    if (temp.length &gt; 0) {
        result.push(temp);
    }
    angular.copy(result, input);
    input.grouped = true;
    return input;
  }; 
  }).
  </code></pre>
  
  <p>Note both the use of <code>angular.copy</code> and the <code>.grouped</code> marker on input, but to no avail :(
  I am aware of <em>e.g.</em> <a href="https://stackoverflow.com/questions/13277542/10-digest-iterations-reached-aborting-due-to-filter-using-angularjs">&quot;10 $digest() iterations reached. Aborting!&quot; due to filter using angularjs</a> but obviously I did not get it.</p>
  
  <p>Moreover, I guess the grouping logic is a bit naive, but that's another story. Any help would be greatly appreciated, as this is driving me crazy.</p>