1
私は2の単純なモデルを持っています。私は毎秒html.getが実行されますが、ビューに配置された変数はそれ自体をリフレッシュしません。何が問題ですか ?Angular2間隔1のhttp.getはビューを更新しません
constructor(private _cm: Communication) {}
ngOnInit() {
setInterval(() => {
this.getDeviceData();
this.numCountChange.next(this.responseDate)
}, 1000);
}
ngOnDestroy() {
clearInterval(this.requestInterval);
}
getDeviceData() {
this._cm.devicesService.getAccessPointStateByIdDeviceAndIdAccessPoint(10018, 10154)
.subscribe(
accessPoint => {
this.device0 = accessPoint;
this.device0.stateChecker();
this.responseDate = new Date()
console.log(this.responseDate);
},
error => console.log(error)
);
}
HTMLは:
< div class="small-box-footer">
{{ responseDate }}
< /div>
responseDateは、すべての時間を示して最初の応答値
このソリューションは動作しますが、私は別のエラーを表示するためのリンクが EXCEPTION発生し得るとき:破壊されたビューを使用しようとしていますトリッキーな例外ザッツdetectChanges – Emerceen
を。 'this.subscription = this._cm.deviceService.getAccessPoint ... subscribe()'や 'ngOnDestroy() 'のようなクラスプロパティ(例えば' subscription')に 'subscribe'の戻り値を格納してみてください。 'this.subscription.unsubscribe()'を呼び出しますか? –