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>
stibay
  • 1,200
  • 6
  • 23
  • 44
  • 2
    ng-if = `*ngIf` – eko Aug 16 '17 at 13:01
  • 1
    Please provide the expected output in your question, because I don't understand what you mean here. – n00dl3 Aug 16 '17 at 13:07
  • 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. – stibay Aug 16 '17 at 13:10
  • Same as here: https://stackoverflow.com/questions/27211799/angular-ng-repeat-add-bootstrap-row-every-3-or-4-cols but with using bulma and angular 4 – stibay Aug 16 '17 at 13:11

2 Answers2

4

change the condition in *ngIf as below.

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

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

Younis Ar M
  • 913
  • 6
  • 15
  • 1
    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](https://plnkr.co/edit/CUXb1ubGBNUW13KUAm2b?p=preview) :) – Nehal Aug 16 '17 at 14:36
  • 4
    howcome plunker just says `loading...` ?? cant see any of you guys example rendered on the html. Did I miss anything? – Gel Sep 05 '19 at 21:06
1

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

Abdullah
  • 2,393
  • 1
  • 16
  • 29