我正在尝试显示倒数计时器,但我很难过。我基本上存储 a startTime
,然后使用管道计算并显示差异。
这是我的管道
@Pipe({
name: "timeDiff",
pure: false
})
export class TimeDifferencePipe implements PipeTransform {
transform(start: Date, end?: Date): string {
if (start === null) return "";
end = Util.isDate(end) ? end : new Date();
let diff = new Date(end.getTime() - start.getTime());
let min = diff.getMinutes();
let sec = diff.getSeconds();
let mil = diff.getMilliseconds();
return `${min}:${("00" + sec).substr(-2, 2)}:${("0000" + mil).substr(-4, 4)}`;
}
}
代码有效,但我得到了错误Expression has changed after it was checked. Previous value: '0:00:0004'. Current value: '0:00:0008'.
我知道幂等表达式,但是如何显示具有高变化频率的数据呢?