Setting value in mat-slider

Advertisements

How to set an initial value on the angular range slider?

According to the Angular material documentation, the code should be like this:

<mat-slider min="1" max="5" step="0.5" value="1.5">
  <input matSliderThumb>
</mat-slider>

However, it does not seem to set a default value.

Here is the stackblitz provided by the angular documentation, with the attributes added: https://stackblitz.com/edit/7nqkex?file=src%2Fexample%2Fslider-overview-example.html

>Solution :

You have a input inside themat-slider, so you should put the value there, not to <mat-slider>.

Try this:

<mat-slider min="1" max="5" step="0.5">
  <input matSliderThumb value="1.5" />
</mat-slider>

Leave a ReplyCancel reply