Skip to main content

angular material - How to use Slide toggle change event

app.component.ts

import { Component } from '@angular/core';
import { MatSlideToggle } from '@angular/material/slide-toggle';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})


export class AppComponent { 
  message:string = "";

  onSlideToggleChange(slideToggle:MatSlideToggle){
    this.message = "Slide toggle checked change to : "
      + slideToggle.checked
  }
}
app.component.html

<h2 style="padding-top:25px; padding-bottom:25px;">
  Angular Material - How to use Slide toggle change event
</h2>


<h3>{{message}}</h3>

<mat-slide-toggle 
  #slideToggle
  (change)="onSlideToggleChange(slideToggle)">
    Allow location access
</mat-slide-toggle>
app.module.ts [import]

import { MatSlideToggleModule } from '@angular/material/slide-toggle'
More Angular tutorials