I am looping on a collection of models and want to show one element per model. However, for CSS reasons, I must add another element when I reach the forth model (I need to add a Bootstrap clearfix
element for the layout to look good).
<div class="jumbotron">
<ol class="row">
<li *ngFor="#card of deck; #i = index" class="col-xs-3">
<h3>{{ card.name }}</h3>
</li>
</ol>
</div>
How do I say if (i + 1) % 4 === 0
, then add this li
plus another <li class="clearfix"></li>
?
This can be done with the
<ng-container>
helper elementAn alternative approach (used before
<ng-container>
became available)This can be done with the long
ngFor
form with an explicit<template>
tag likePlunker example
See also https://angular.io/docs/ts/latest/api/common/index/NgFor-directive.html