Hello i am trying to update a HTML value based on the current Date
.
What i am doing is declare a variable inside my component
and update it in the handler
argument of window.setInterval
.
I have tried both with my variable as a string and thinking it might be a closure
problem i wrapped it in an object to no avail.My component variable gets updated (i print it in the console) but it does not update in the HTML
.
Component
export class AppComponent {
title = 'quickapp';
public date:string;
private subr:number;
private onTime(){
this.date=new Date().getTime().toString()
console.log("Date="+this.date);
}
ngOnInit(): void {
this.subr=window.setInterval(this.onTime,2000);
}
}
HTML
<p>{{this.date}}</p>
P.S: The console.log
line works and the date seems to be updating.Why do i not see anything in the HTML?
Console Output
Date=1542120062788
Date=1542120064788
Date=1542120066788