I am trying to build an angular project . In my project I want to show a list of books ,I have a SmallBookView Component for a single book and I want to use ngFor to show many other books./ however after every 3 books I need to add a div to separate this books, In the end it should look like so
<app-small-book-view></app-small-book-view>
<app-small-book-view></app-small-book-view>
<app-small-book-view></app-small-book-view>
<div class="clearfix"> </div>
<app-small-book-view></app-small-book-view>
<app-small-book-view></app-small-book-view>
<app-small-book-view></app-small-book-view>
<div class="clearfix"> </div>
<app-small-book-view></app-small-book-view>
<app-small-book-view></app-small-book-view>
<app-small-book-view></app-small-book-view>
<div class="clearfix"> </div>
the div separate each line of books in the ui. I am trying to use ngFor like so
<app-small-book-view *ngFor="let i of [1,2,3,4,5,6,7]; let _i = index">
<div class="clearfix" *ngIf="(_i % 3) == 0"></div>
</app-small-book-view>
but this is adding the div only inside the SmallBookView instead of between them, how do I add this div between the components>
*ngIf="(_i % 3) == 0"
will create a div after the firstapp-small-book-view
and after every third element afterwards instead of after the thirdapp-small-book-view
as is what is desired. This is because the indexing is zero-based and(0 % 3) == 0
. You might want*ngIf="(_i % 3) == 2"
instead to add a div after every third element. – Novelty