如果真的要做push notification啥的,还是要从service端设计.
private startTime: number = new Date().getTime();
private theValue: number = 0;
private FIVE_SECONDS: number = 5000;
private getUpdate(): void {
let currentTime = new Date().getTime();
let diff = currentTime - this.startTime;
if (diff / FIVE_SECONDS > 0) {
// Do something
this.theValue += 1;
this.startTime = new Date().getTime();
}
}
}
我再看了一下问题, 貌似你是想要找个简单的function咯,可以这样:
import { Observable } from 'rxjs/Rx';
// .....
export Class AppComponent {
private theValue: number = 0;
ngOnInit() {
let timer = Observable.timer('some time', 2000);
timer.subscribe(t => this.theValue += 1);
}
}
这样就好啦,用一个Observable,然后subscribe,再在event里面作改变就好咯