I'm having an issue with a function that toggles a mat-slide-toggle. I need to modify this function to only toggle when the result is false. Currently, it toggles every time, regardless of the result being true or false. I want it to not toggle when the result is false.
Component ts
onActiveHomeboxP(homeboxpackageid, activeid, elem) {
this.areWeWaiting = true;
if (confirm('Are you sure to change Status?')) {
let editHomeboxp = new HomeboxP(
this.activeHomeboxPForm.value
);
editHomeboxp.homeboxpackage_id = homeboxpackageid;
editHomeboxp.active = !activeid ? 1 : 0;
this.ws.activatehomeboxp(editHomeboxp).subscribe(
result => {
if (result === true) {
this.router.navigate(['/hbp']);
} else {
this.areWeWaiting = false;
}
},
error => {
}
);
} else {
elem.checked = !elem.checked;
}
}
component html
<form [formGroup]="activeHomeboxPForm" class="col s12" >
<span *ngIf="item.active === 1" >
<section class="example-section">
<mat-slide-toggle formControlName="active-{{item.homeboxpackage_id}}" class="example-margin" [checked]="item.active === 1" #elem (click)="onActiveHomeboxP(item.homeboxpackage_id, item.active, elem)" >
</mat-slide-toggle>
</section>
</span>
<span *ngIf="item.active === 0" >
<section class="example-section">
<mat-slide-toggle formControlName="active-{{item.homeboxpackage_id}}" class="example-margin" [checked]="item.active === 0" #elem (click)="onActiveHomeboxP(item.homeboxpackage_id, item.active, elem)">
</mat-slide-toggle>
</section>
</span>
</form>
I would appreciate any suggestions on how to prevent the switch from toggling when the result is false. Thank you