Condition Alert with NgFor


#1

I want to achieve a popup if i get a null on my ngfor

    <ion-select interface="popover" [ngModel]="selectedKidId">
      <ion-option *ngFor="let kid of kids" [value]="kid.id">{{kid.name}}</ion-option>
    </ion-select>
  </ion-item>

This will show me a list of kids name, i want to get a pop up if there is no kid on the list. is there a way to do it ?

and instead of the list i’ll get a popup or a call to a modal.

Thank you


#2

Can you just use ngIf?

    <ion-select *ngIf="kids" interface="popover" [ngModel]="selectedKidId">
      <ion-option *ngFor="let kid of kids" [value]="kid.id">{{kid.name}}</ion-option>
    </ion-select>

    <div *ngIf="!kids">Dang, no kids...</div>

If not, you might need to handle this in your component class, e.g.

  ionViewDidEnter() {
       if (!this.kids) {
         // do modal
       }
   }