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

232
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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