Search code examples
angularmaterial-designangular-material

Usage of MatSlideToggleChange Event of mat-slide-toggle


I'm trying to use a switch in a form to toggle the appearance of one of two dropdown menus in the same form.

Can I use the MatSlideToggleChange event emitted by a MatSlide class toggle to achieve my desired result?


Solution

  • you can use output change property to toogle its change value

    <mat-slide-toggle
       [ngModel]="checked"
       (change)="changed()"
       class="example-margin"
       [color]="color"
    >
       Slide me! {{checked}}
    </mat-slide-toggle>
    

    component

    color = 'accent';
    checked = false;
    
      changed(){
        console.log(this.checked)
      }
    

    demo stackblitz