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.
try this
var date = new Date();
if (date.getDate() == 26 && date.getMonth() == 3) {
document.body.style.background = "red";
} //this works
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;
}
}