Skip to main content

angular material - How to use Slider input event

app.component.ts

import { Component } from '@angular/core';
import { MatSlider } from '@angular/material/slider';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styles: [`
    mat-slider{
      width: 400px;
    }
  `]
})


export class AppComponent { 
  value:number = 0;
  message:string = "";

  onSliderThumbMove(slider:MatSlider){
    this.message = "Slider thumb moved to " + slider.value;
  }
}
app.component.html

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


<h3>Selected Value : {{value}}</h3>

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

<mat-slider
    #slider
    [(ngModel)]="value"
    (input)="onSliderThumbMove(slider)">
</mat-slider>
app.module.ts [import]

import { MatSliderModule } from '@angular/material/slider';
import { FormsModule } from '@angular/forms';
More Angular tutorials