Topic: disable switch programatically
how do i disable a switch programatically. with a variable for instance that can change value in the .ts something like disabled="true"
Konrad Stępień staff answered 5 years ago
Hi @moulot,
You can use [disabled]="variable"
property in your code.
Like this:
<!-- Material switch -->
<div class="switch">
<label>
Off
<input type="checkbox" (change)="toggle($event)">
<span class="lever"></span> On
</label>
</div>
<!-- Material switch -->
<div class="switch">
<label>
Off
<input type="checkbox" [disabled]="disable">
<span class="lever"></span> On
</label>
</div>
And ts:
import {Component} from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
disable = false;
toggle = (event: any) => {
this.disable = event.target.checked;
}
}
Best, Konrad.
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Pro
- Premium support: Yes
- Technology: MDB Angular
- MDB Version: 9.0.0
- Device: dell notebook
- Browser: chrome
- OS: windows 10
- Provided sample code: No
- Provided link: No