Angular 4 *ngFor adding a row div every third column
Asked Answered
F

2

6

I am using Angular 4 with the bulma css framework and I am wondering how I can add a new row (or columns class) every third column.

The index variable which prints out 0,1,2 0,1,2 etc. was when I looking at a snippet when using bootstrap.

Noticed some comments on maybe I can use the template syntax but didn't get that to work either.

<div class="columns">
    <div class="column is-one-third" *ngFor="let item of items | async; let index = index">
      <app-item-details [item]='item '></app-item-details>
      {{ index % 3 }}
    <div class="is-clearfix" *ngIf="index % 3 == 0"></div>
  </div>
</div>
February answered 16/8, 2017 at 13:0 Comment(4)
ng-if = *ngIfLeptospirosis
Please provide the expected output in your question, because I don't understand what you mean here.Aegeus
Yea noticed I type that *ngIf wrong, but that is for the bootstrap snippet so didn't expect that to work when using the bulma framework. (it didn't help either) What I need is to wrap my result around a new columns class every third item in loop.February
Same as here: #27212299 but with using bulma and angular 4February
T
4

change the condition in *ngIf as below.

*ngIf="(index + 1) % 4 == 0"

Plunker example : https://plnkr.co/edit/C0DrgY3Rty33ZRhyML7E?p=preview

Toinette answered 16/8, 2017 at 13:33 Comment(2)
I think the OP wants to add a div after every 3, in your plunker after first iteration, row gets added after every 4. So, I made some tweaks to your plunker :)Briant
howcome plunker just says loading... ?? cant see any of you guys example rendered on the html. Did I miss anything?Lumpfish
C
2

Below Solution work for me:

<div class="form-group">
    <div class="row">
        <div class="col-xl-4" *ngFor="let item of productimages; let index = index">
            <img [src]="item.image">
        </div>
    </div>
</div>

enter image description here

Crease answered 22/5, 2020 at 18:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.