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

176
Visualizações
Replace a substring by a rxjs countdowntimer

I am trying to implement a countdowntimer using rxjs in my angular 12 application. In my ts I have :

let timeLeft$ = interval(1000).pipe(
  map(x => this.calcTimeDiff(orderCutOffTime)),
  shareReplay(1)
);

calcTimeDiff() will return seconds, minutes and hours;

I have to create a string out of this and display that in the HTML. Basically replace an existing word in the string with timeLeft$ which will be a countdowntimer to be shown in the HTML.

Something like : this.orderCutOffMessage = someString.replace('Down', timeLeft$)

https://henrikmassow.medium.com/implement-a-countdown-timer-with-rxjs-in-angular-61600d1af00c

orderCutOffTime = "1645567200000" // Unix timestamp in milliseconds

private calcTimeDiff(cutOffTime: any): timeComponents {
const finalCutOffTime = (cutOffTime).valueOf();
const milliSecondsInASecond = 1000;
const hoursInADay = 24;
const minutesInAnHour = 60;
const secondsInAMinute = 60;
const timeDifference = finalCutOffTime - Date.now();

const hoursToFinalCutOffTime = Math.floor(
  (timeDifference /
    (milliSecondsInASecond * minutesInAnHour * secondsInAMinute)) %
  hoursInADay
);

const minutesToFinalCutOffTime = Math.floor(
  (timeDifference / (milliSecondsInASecond * minutesInAnHour)) %
  secondsInAMinute
);

const secondsToFinalCutOffTime =
  Math.floor(timeDifference / milliSecondsInASecond) % secondsInAMinute;


return { secondsToFinalCutOffTime, minutesToFinalCutOffTime, hoursToFinalCutOffTime };

}

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

0

Here's a working example of your code https://stackblitz.com/edit/angular-material-table-data-source-znbvdb. It's basicly almost like the one in the link you shared, except that the names of the vars have been changed, one var discarded (days) and everything put in one .ts file. Please let me know if that's what you are looking for. Your orderCutOffTime has been hard-coded, but you are probably getting it in some subscription so you can tweak it. Also, timeString propably comes from subscription too.

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