【发布时间】:2019-09-26 19:49:11
【问题描述】:
我正在订阅一个间隔,如果出现错误,应该取消订阅该间隔。同样在 ngDestroy 上它应该取消描述。但是,当我转到我网站上的另一个组件时,我仍然可以看到它轮询服务器的位置。
使用 rxjs 6.2.1
这是我的代码
private polling: Subscription;
ngOnDestroy() {
if(this.polling){
this.polling.unsubscribe();
}
}
loadContacts(){
this.polling = interval(10000)
.subscribe((val) => {
this.resourceService.getQueryUserPresence(this.contacts[0].Email).subscribe((response) => {
console.log('polling for ' + fullName);
}, (error: any)=> {
console.log('Error Getting Status: ' + error)
if(this.polling){
this.polling.unsubscribe();
}
});
}, (error: any)=> {
console.log('Error polling: ' + error)
if(this.polling){
this.polling.unsubscribe();
}
})
}
【问题讨论】:
标签: angular typescript