Ionic 5, ionic checkbox so late behavior


I tried to bind checked attribute value on ion-checbox but the behavior is a bit late. on my ts file i have an array variable user_id and on my checkbox list i put an action to fill this array depend on which checkbox is checked, and then verify to make the value of checked attribut:

<ion-checkbox [checked]"user_id.includes( ? true : false" (click)"AddUser(user)"><ion-checkbox>

the user_idis filled and the value of checked change but the checkbox seem not checked, and when i tried to recheck the checkbox, the value change to false but the checkbox seem checked. I’ve put some functionnalit√© to make condition (example variable type)if the value is true so the checkboxlist is not shown, and with that functionnality, when the value of type switch from false to true, the wheckbox work well but the behavior is bit late at the moment when the checbox is checked for the first time


click event is working properly with my checkbox and retrieving data is not consistent


Please refer to Ionic documentation on ion-checkbox

using the (click) to capture the action on a checkbox is wrong.

I suggest you use (ionChange) event to trigger your addUser() function.

With [(checked)] binding, it will create an automatic sync between your actions and the values you save.

Answered By – Haythem

Leave a Comment