Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!