eulercode
eulercode

Reputation: 1157

How to debug on whether observable is unsubscribe

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()

Upvotes: 10

Views: 12345

Answers (2)

Mathias Gheno
Mathias Gheno

Reputation: 787

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;

Upvotes: 3

alexKhymenko
alexKhymenko

Reputation: 5598

You can have a subscription and check closed parameter.

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

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

Upvotes: 16

Related Questions