Question: How would I use AngularJS `ng-repeat` to display the following HTML (Twitter Bootstrap Scaffolding)? Essentially, every third record I need to close the `</div>`, print an `<hr>`, then open another `<div class="span4">` 

```
    <div class="row">
      <div class="span4">
        <h3>
          Project A
        </h3>
      </div>
      <div class="span4">
        <h3>
          Project B
        </h3>
      </div>
      <div class="span4">
        <h3>
          Project C
        </h3>
      </div>
    </div>

    <hr>

    <div class="row">
      <div class="span4">
        <h3>
          Project D
        </h3>
      </div>
      <div class="span4">
        <h3>
          Lab Title
        </h3>
      </div>
      <div class="span4">
        <h3>
          Project E
        </h3>
      </div>
    </div>

```

I've created a fiddle for code demos.  

<http://jsfiddle.net/ADukg/261/>

Answer: 
Here's a way:

```
<div ng-controller="MyCtrl">
  <div ng-repeat="project in projects">
    <span ng-if="$index % 3 == 0">
      <hr />
      <div class="row">
        <h3 class="span4" ng-if="projects[$index+0]">{{projects[$index+0]}}</h3>
        <h3 class="span4" ng-if="projects[$index+1]">{{projects[$index+1]}}</h3>
        <h3 class="span4" ng-if="projects[$index+2]">{{projects[$index+2]}}</h3>
      </div>
    </span>
  </div>
</div>

```

This way will also work if you have for example 7 data items: on the last 3 data, it will only show item 7 and not try to show the nonexistant item 8 and 9.

<http://jsfiddle.net/4LhN9/68/>

**EDIT**: Updated to use ng-if & angular 1.2.12
To keep view logic out of the controller and have a more re-usable solution, you can create a custom filter that splits the array into row groups:

```
angular.module('app').filter('group', function() {
    /**
     * splits an array into groups of the given size
     * e.g. ([1, 2, 3, 4, 5], 2) -> [[1, 2], [3, 4], [5]]
     */
    return function(array, groupSize) {
        return _.groupBy(array, function(val, index) {
            return Math.floor(index / groupSize);
        });
    };
});

```

And in the view:

```
<div class="row" ng-repeat="group in projects | group:3">
   <div class="span4" ng-repeat="project in group">
      {{project}}
   </div>
</div>

```

To include the hr you can use the ng-repeat start and end points:

```
<div class="row" ng-repeat-start="group in projects | group:3">
   <div class="span4" ng-repeat="project in group">
      {{project}}
   </div>
</div>
<hr ng-repeat-end />

```