Dynamically enable/disable the checkbox


#1

Im working with checkboxes, what I want to do is disable/enable it on certain condition. but the problem is disabled=true is working but disabled=false is not, is there any way to enable=true/false?

Moreover, I’m placing my vars in place of true/false as Boolean to turn on/off the checkbox.

Any idea how to achieve this?

Thanks


#2

Did you try ngSwitch? I faced an issue for popover and I solved it using the same.


#3

Ihave achieved this using ngIf but I dont want to create two different checkbox tags.
This is my code, but Im finding a better way to achieve this using bool var and placing it for the disabled property.

<ion-checkbox color=“primary” disabled=“true” *ngIf="!completed">
<ion-checkbox color=“primary” *ngIf=“completed”>

PS: Preview is removing the closing tags of ion-checkbox.


#4

Try this:

<ion-checkbox color=“primary” [attr.disabled]=“!completed”></ion-checkbox>


#5

I would instead bind disabled to completed so that you only 1 ion-checkbox.

<ion-checkbox color=“primary” [disabled]=“completed”>

Setting completed to true or false to disabled/enable the checkbox.


#6

Thank you so much brother.
This is what I was looking for <3