mat-slide-toggle shouldn't change it's state when I click cancel in confirmation window
Unfortunately you cannot use stopPropagation
with mat-slide-toggle
, you will need to programmatically set the checked value back to true
on the event in your else condition.
else {
e.source.checked = true;
console.log("toggle should not change if I click the cancel button")
}
Stackblitz
https://stackblitz.com/edit/angular-79yf7m?embed=1&file=app/slide-toggle-overview-example.ts
You can prevent the toggle mechanism by listening for click event and then event.preventDefault() / event.stopImmediatePropagation(). Then open your dialog and according to the user selection you toggle the toggle yourself or not: toggleReference.toggle().
No need to set it back to true.