i have used setInterval() method to show current datetime in my angular 6 project.But datatime variable value not changing after setInterval() call.its taking onload value.Here is my code
.ts
constructor(private data: DataService) {
this.data.get_data('current-gmt-date',true)//service call
.subscribe((data:any) => {
this.now = data.data.currentDateTime;//2019-01-21 20:30:0
});
setInterval(() => {
this.now.setSeconds( this.now.getSeconds() + 1 );
console.log(this.now);
}, 1000);
}
And .html
<span class="dateClock">Time: {{now | date:'yyyy-MM-dd H:mm:ss ' : 'UTC' }}</span>