Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

177
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda