【发布时间】:2018-03-08 07:51:35
【问题描述】:
是的,我在网上搜索并阅读了很多讨论,但都没有回答我的问题!!!
Angular/RxJs When should I unsubscribe from `Subscription`
Angular 2 Subscribe / Unsubscribe Observables in case of http calls
我的任务是: 角度(2+)http-response 流,我是否需要在重新使用它之后或之前取消订阅? 说,我有:
private mystream$: Subscription;
public MyTask(){
if (this.mystream$){ this.mystream$.unsubscribe }
this.mystream$ = http.get(url).subscribe({
// to do
})
}
ngOnDestroy() {
if (this.mystream$) { this.mystream$.unsubscribe(); }
}
所有我读过的,在使用前取消订阅 onDestroy 和流变量检查是没有必要的,但我还没有被说服,因为我通过互联网调用 http.put ,没有保证,它将是或必须是在应用程序之前完成以再次调用 MyTask()。
请告诉我为什么我错了,这个 http.put 流在使用前检查和清理是没有必要的,即使是通过互联网打电话,我的用户也不是耐心的。
【问题讨论】:
-
只是意识到rxjs或observable没有“取消令牌”功能可以解决我的担心
-
所以,httpclient 的 shareReplay() 应该让我放心
标签: angular http rxjs observable