You do not need to do this, because for an HTTP-observable, the call ends immediately after the action is completed.
From the sources of the sources, I see that when unsubscribing, an error is caused and terminates.
protected _error(err: any): void { this.destination.error(err); this.unsubscribe(); } protected _complete(): void { this.destination.complete(); this.unsubscribe(); }
I went ahead and did a little experiment by adding unsubscribe with a timeout
var subscription = this.http.get(`apiurl`) .subscribe(response => { setTimeout(function(){ debugger; subscription.unsubscribe(); }, 30); });
if i'm inside unsibscribe on
Subscriber.prototype.unsubscribe = function () { if (this.closed) { // this.closed is true return; } this.isStopped = true; _super.prototype.unsubscribe.call(this); };
Then this.closed == true , which means unsubscribing.
So, yes, now I can say that you do not need to unsubscribe :)
source share