How to debug on whether observable is unsubscribe

自古美人都是妖i 提交于 2019-12-10 17:16:54

问题


how can i test whether the observable is unsubscribe after subscription. I am developing in ionic2/angular2.

I am expecting typing something like this in chrome developer mode and it will return value: observableName.isSubscribe()


回答1:


You can have a subscription and check closed parameter.

let subscription = observable.subscribe(() => {})

if (!subscription.closed) {
  //subscribed
} else {
  //not subscribed
}



回答2:


As sebaferreras told in the last comment, you can just use the closed property;

So, for example:

const sub$ = new Subject();
sub$.unsubscribe();
sub$.closed //true;


来源:https://stackoverflow.com/questions/46221549/how-to-debug-on-whether-observable-is-unsubscribe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!