Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
How to create a slider with specified dates to choose from

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

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

interesting challenge. I think you should reconsider using number as there exists something called Unix Epoch Time. You can read more about it here. Basically it is a representation of time in terms of seconds since 1st January of 1970.

You could use this to define the values of your different options. And the choose the appropriate step value.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use the displayWith input of a mat slider to define the label that should be displayed according to the selected value of the slider.

The Slider component documentation provides a StackBlitz https://stackblitz.com/angular/akebpxkvdvq?file=src%2Fapp%2Fslider-formatting-example.ts where you can see a formating method used to transform values greather than 1000 with a 'k'.

I'm pretty sure you can come up with a way of using a formatting method to answer your problem.

Maybe you can define a Map containing all your acceptable values using this kind of format (as json for example)

{value1:{labelToDisplay,actualDateObject},value2:{labelToDisplay,actualDateObject}}

Through displayWith input you can display the map.get(pickerValue).labelToDisplay and if you need to manipulate the actual date you can use map.get(pickerValue).actualDateObject

Edit: You can find a proof of concept (really a basic draft) on this stackblitz https://stackblitz.com/edit/angular-x1egtw?file=src%2Fapp%2Fslider-formatting-example.ts

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda