Anyone know why my variables aren't being displayed on my page? I'm creating a countdown timer, and the variables are being updated, but not displayed on my page. Not really sure what the problem is. It's console logging the days out every second like it should, but it's not displaying on my site when I have {{days}}
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-fireworks',
templateUrl: './fireworks.component.html',
styleUrls: ['./fireworks.component.scss']
})
export class FireworksComponent implements OnInit {
public days;
public hours;
public minutes;
public seconds;
constructor() { }
ngOnInit() {
let time = new Date("July 4, 2020 00:00:00").getTime();
let x = setInterval(function() {
let now = new Date().getTime();
let distance = time - now;
this.days = Math.floor(distance / (1000 * 60 * 60 * 24));
this.hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
this.minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
this.seconds = Math.floor((distance % (1000 * 60)) / 1000);
console.log(this.days)
if (distance < 0) {
clearInterval(x);
}
}, 1000);
}
}
Template:
<h1>test</h1>
<p>{{days}}</p>