Answer the question
In order to leave comments, you need to log in
How to start timer in Angular2 pipe?
There is a pipe that shows the time difference.
import {Pipe} from "@angular/core";
@Pipe({name: 'ago'})
export class AgoPipe {
transform(date: Date): string {
return timeDifference(date);
}
}
function timeDifference() {...}
import { Component, Input } from '@angular/core';
import { Subscription, Observable } from 'rxjs';
@Component({
selector: 'ago-renderer',
template: `<span>{{ago}}</span>`,
styles: [`:host {display: inline}`]
})
export class AgoRendererComponent {
@Input() time: any;
timer: Subscription;
ago: any;
ngOnInit() {
this.timer = Observable.interval(5000).subscribe(() => {
this.ago = timeDifferenceHumanise(this.time);
});
}
ngOnDestroy() {
this.timer.unsubscribe();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question