How to check if a checkbox is checked?


#1

Hello, I want to to show an element with *ngIf only if checkbox is checked, how please ?


#2
 <ion-item>
    <ion-label>Pizza</ion-label>
    <ion-checkbox [(ngModel)]="checkboxpizza"></ion-checkbox>
  </ion-item>
<div *ngif="checkboxpizza>

pizza selected
</div>

#3

Thanks but It don’t work, I finaly succeeded like this :

<ion-checkbox (click)="toggleCheckbox()"></ion-checkbox>
<div *ngIf="showItem">
<div>
showItem: boolean;

toggleCheckbox() {
    this.showItem = !this.showItem;
  }

#4

You can change that to this.showItem = false.
It’s more in line with standards and drives home the fact that you can toggle bound booleans true/false to add and remove elements (and it keeps the variable in an actual boolean state)


#5

You means

  toggleCheckbox() {
    this.showItem = false;
  }

?
It’s not work for me


#6

Never mind then :slight_smile:


#7

Buena men, tal cual lo q necesitaba…


#8

hi it,s working for me *ngIf=‘lumber’
but if i want to use for two ngmodel *ngIf=‘lumber’ || =‘logs’ is not working for me…
please state how to ngif for two ngmodel