Topic: mdb-switch state
Aram Sabir pro answered 6 years ago
Thanks a lot, also you can get switch state by ngModel:
<html>
switchState(){
console.log(this.model)
}
<input type="checkbox" [(ngModel)]='model' >
<button mdbBtn color="primary" (change)="switchState()">Switch state</button><ts>
Damian Gemza staff answered 6 years ago
Dear IT Infrastructure,
You can change the switch state by using ViewChild and Renderer2 classes.
Add Angular identifier to the input element (#switch), and create a button with a method on click. In this method with renderer set checked attribute to true or false.
Please take a look at below code:
html:
ts:
Best Regards,
Damian
<!-- Switch --> <div class="switch"> <label> Off <input #switchtype="checkbox"> <span class="lever"></span> On </label> </div> <button mdbBtn color="primary" (click)="switchState()">Switch state</button>
@ViewChild('switch') switch: ElementRef; constructor(privaterenderer:Renderer2) {} switchState() { this.renderer.setAttribute(this.switch.nativeElement, 'checked', 'true'); }
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Status
Resolved
Specification of the issue
- ForumUser: Pro
- Premium support: No
- Technology: MDB Angular
- MDB Version: 6.2.2
- Device: no
- Browser: chrome
- OS: windows
- Provided sample code: No
- Provided link: No