2020-02-16 16:15:07 +01:00
|
|
|
import { Component, OnInit, OnDestroy, ChangeDetectionStrategy, Input, ChangeDetectorRef } from '@angular/core';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-time-since',
|
|
|
|
template: `{{ time | timeSince : trigger }}`,
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
|
|
})
|
|
|
|
export class TimeSinceComponent implements OnInit, OnDestroy {
|
|
|
|
interval: number;
|
|
|
|
trigger = 0;
|
|
|
|
|
|
|
|
@Input() time: number;
|
2020-02-27 19:09:07 +01:00
|
|
|
@Input() fastRender = false;
|
2020-02-16 16:15:07 +01:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private ref: ChangeDetectorRef
|
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.interval = window.setInterval(() => {
|
|
|
|
this.trigger++;
|
|
|
|
this.ref.markForCheck();
|
2020-02-27 19:09:07 +01:00
|
|
|
}, 1000 * (this.fastRender ? 1 : 60));
|
2020-02-16 16:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
clearInterval(this.interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|