angularmat-slider

Change value of mat-slider to default value on click of button


<mat-slider thumbLabel min="0" max="100" step="1" value="0" >

<button type="button" (click)="Refresh()">Click Me!</button>

Refresh(){
// What should be written in this

}

Suppose I changed this slider and when I click on refresh button, I need to adjust the value again to zero

Can any one explain how to do it..

ThankYou....!!!!


Solution

  • Simply add value as ngModel to change it as needed

    Here is a stackblitz example

    ts

    value: number = 0
    
    Refresh(){
      this.value = 0
    }
    

    html

    <mat-slider thumbLabel min="0" max="100" step="1" [(ngModel)]="value" ></mat-slider>
    <button type="button" (click)="Refresh()">Click Me!</button>