【发布时间】:2019-06-15 02:39:33
【问题描述】:
我已经使用 setInterval() 方法在我的 Angular 6 项目中显示当前日期时间。但是在 setInterval() 调用之后数据时间变量值没有改变。它采用 onload 值。这是我的代码
.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);
}
还有.html
<span class="dateClock">Time: {{now | date:'yyyy-MM-dd H:mm:ss ' : 'UTC' }}</span>
【问题讨论】: