Search code examples
angularjsangularjs-scope

ng-repeat X for 5 times, then Y once and continue repeating X


Is it possible to set ng-repeat to repeat items X from an array 5 times, then add item Y, and continue repeating X.

The desired result would be:

<div>{{x.item}}</div>
<div>{{x.item}}</div>
<div>{{x.item}}</div>
<div>{{x.item}}</div>
<div>{{x.item}}</div>
<div>{{y.item}}</div>
<div>{{x.item}}</div>
<div>{{x.item}}</div>

...

I hope that explains it. Y item could also be a div whose contents do not come from said array.


Solution

  • You may doing something like:

    <div ng-repeat-start="x in items">
        {{x.item}}
    </div>
    <div ng-repeat-end ng-if="$index === 5">
        {{y.item}}
    </div>