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

233
Vistas
Angular 2 - change app background on specific day

As an easter egg for my colleagues, I'd like to change the site background every year on the 4th of May. I can't seem to get a handle on how that would work. So far I've tried this to test a method of doing it:

var date = new Date();
if (date.getDate() == 26 && date.getMonth() == 4) {
  document.body.style.background = "red";
}

I've placed it in the root component's ngOnInit but it doesn't seem to do anything.

If anyone could shed some light it would be very much appreciated. I'd like to do it as a sort of 'parting gift' to my colleagues as it is my last day in the office.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

try this

var date = new Date();
if (date.getDate() == 26 && date.getMonth() == 3) {
  document.body.style.background = "red";
} //this works
over 4 years ago · Santiago Trujillo Denunciar

0

Maybe a better way is to use a specific class for that.

<div [ngClass]="'bg-red': checkDate()">

CSS

.bg-red { background-color: red; }

TS

checkDate() {
    var date = new Date();
    if(date.getDate() == 26 && date.getMonth() + 1 == 4){
         return true;
    }
}
over 4 years ago · Santiago Trujillo 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