I am trying to toggle
the toggle()
via code:
template
<mat-slide-toggle color="primary" (change)="updateFunc($event)"></mat-slide-toggle>
ts
updateFunc(e) {
// do some checks to see if can be activated
// if can't be activated, don't slide to on
e.checked = false; // <--- does not work
e.toggle(); // <-- does not work
}
Any ideas?
--EDIT--
To clarify, after the change event, the button is toggled to on. My function is run to do some tests. If the tests do not pass, I want to toggle the slider back to the off position. So, how do I toggle the button (on or off) in my code? This is simply a question of using the toggle() method in my code, or unchecking the switch in my code.
mat-slide-toggle
has an input propertychecked
, initially you assign this to eithertrue
orfalse
then onchange
event, you can toggle it. – Antilogarithm