address.page.html
<ion-toggle [checked]="newAddressDefaultVal" (ionChange)="onChangeToggle($event)">
defaultStatus is fetched from the firestore and if the defaultStatus is true, we won't let the user to switch the toggle off. In address.page.ts ...
async onChangeToggle(event: any) {
if (event.detail.checked === false && this.defaultStatus === true) {
this.zone.run(() => {
this.newAddressDefaultVal = true;
event.detail.checked = true;
console.log("uncheck failed, checked");
});
}
else if (event.detail.checked === false && this.defaultStatus === false) {
this.newAddressDefaultVal = false;
console.log("unchecked");
}
else if (event.detail.checked === true) {
this.newAddressDefaultVal = true;
event.detail.checked = true;
console.log("checked");
}
}
But only the newAddressDefaultVal data changed and not affect on the toggle. The toggle only on after the page reloaded. I want the toggle always on even when the user click the toggle to off, it must be on again in a short time without page refresh. How can I solve it?