I'm trying to create a slider that only has a few specific options to choose from instead of an entire range. This could be accomplished with a drop-down menu but I think a slider would look a lot better. I'm in an angular project and we're using Material. I can't find a way to get a Material slider or a normal HTML <input> slider to use anything other than numbers. Below is my attempt at it.
HTML
<div class="dateSlider">
<input #dateSlider type="range" id="dateSlider" name="dateSlider"
list="dateList" (change)= "dateChanged()" min={{value}} max = {{value3}}>
<label for="dateSlider">{{currentDate}}</label>
</div>
<datalist id="dateList">
<option>{{value}}</option>
<option>{{value2}}</option>
<option>{{value3}}</option>
</datalist>
TS
private value= new Date('September 27, 2021 14:23:00').toUTCString();
private value2= new Date('September 27, 2021 14:24:00').toUTCString();
private value3= new Date('September 27, 2021 14:25:00').toUTCString();
private currentDate;
dateChanged(){
this.currentDate = this.dateSlider.nativeElement.value;
}
This will set the label to the selected date (in theory). Right now it displays the current value of the slider, which is a number.
EDIT: While I haven't solved my issue exactly, this may be helpful to other people that don't need a varying step (or no step at all). https://stackblitz.com/edit/angular-ktxxwx?file=src/app/slider-overview-example.ts