0

I am trying to use ngIf within an ngFor but it's just breaking my code. Below is my code:

<ion-row *ngIf="{{i % 3}}===0" *ngFor="let category of categories; let i=index">

I need to check if the index mod 3 is equal to zero

3 Answers3

3

You can overwrite your code like:

<ion-row *ngFor="let category of categories; let i=index">
  <ng-container *ngIf="{{i % 3}}===0">
    ...
  </ng-container>
</ion-row>

ng-container behaves the same as template but you can use common syntax like *ngIf and *ngFor

yurzui
  • 205,937
  • 32
  • 433
  • 399
0

you can't put ngIf on the same component as ngFor

kit
  • 4,890
  • 3
  • 24
  • 23
0
  1. Angular disallows such construction
  2. Using i before initializing it in ngFor will never work
  3. If you *ngIf gets a false value the *ngFor would never be created in the first place - see point 1:-)
MatWaligora
  • 1,207
  • 1
  • 12
  • 15