Mark Adesina Omoniyi
Mark Adesina Omoniyi

Reputation: 449

Why is ngIf not working in angularjs2

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

Upvotes: 0

Views: 110

Answers (3)

yurzui
yurzui

Reputation: 214017

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

Upvotes: 3

MatWaligora
MatWaligora

Reputation: 1217

  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:-)

Upvotes: 0

kit
kit

Reputation: 4920

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

Upvotes: 0

Related Questions