Skip to content

Documentation for RxJS Unsubscribing #22410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spottedmahn opened this issue Feb 23, 2018 · 11 comments
Closed

Documentation for RxJS Unsubscribing #22410

spottedmahn opened this issue Feb 23, 2018 · 11 comments
Assignees
Labels
Milestone

Comments

@spottedmahn
Copy link

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Feature request
[X] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

I can't seem to find any information on unsubscribing from RxJS objects in Angular.

I've found a few online articles that discuss it

Expected behavior

It would be nice to get some official guidance on this topic.

Maybe it is there and I just can't find it? I've been googling "angular rxjs unsubscribe"

@ericmartinezr
Copy link
Contributor

See if this PR talks about it #21423. If it doesn't it would be a good idea to ask to be added imo

@spottedmahn
Copy link
Author

spottedmahn commented Feb 23, 2018

Thanks! I reviewed that PR, I don't see anything. I asked... we'll see!

@vicb vicb added feature Issue that requests a new feature comp: docs labels Feb 23, 2018
@ngbot ngbot bot added this to the Backlog milestone Feb 23, 2018
@wKoza
Copy link
Contributor

wKoza commented Feb 24, 2018

This topic is evocated at different places in the documentation. We can find example in the Router documentation ;

When subscribing to an observable in a component, you almost always arrange to unsubscribe when the component is destroyed.
There are a few exceptional observables where this is not necessary. The ActivatedRoute observables are among the exceptions.
The ActivatedRoute and its observables are insulated from the Router itself. The Router destroys a routed component when it is no longer needed and the injected ActivatedRoute dies with it.

Feel free to unsubscribe anyway. It is harmless and never a bad practice.

This explain they are, directly related to a technical element (router, Http) rather than a generaly.

@jasonaden jasonaden self-assigned this Feb 26, 2018
@jasonaden
Copy link
Contributor

This is a good question, and yes, it needs to be documented. I assigned to myself to be addressed in a follow-up to #21423

@jenniferfell
Copy link
Contributor

I added @jbogarthyde as another assignee, so it's on her radar to add this to her backlog for RxJS doc as well.

@seangwright
Copy link

I collected information about this in a SO answer that has some traction (it appears devs are using the approach I document).

I would be happy to update my answer there again to point to the documentation once it's released.

There is also this issue which was closed asking about a specific scenario of what I assume the PR will cover

@spottedmahn
Copy link
Author

Here are some other interesting Stack Overflow posts:

SO Post: Angular2: Unsubscribe from http observable in Service

SO Post: Angular 2 Subscribe / Unsubscribe Observables in case of http calls

@mikaelboff
Copy link

Any updates on this? @jasonaden

@nhays89
Copy link

nhays89 commented Jul 1, 2019

ummm yea I agree. There needs to be more documentation on this subject. Like the OP, I read some articles and saw some guys making suggestions with async pipe and using other rxjs operators, but I would like to hear it from the angular team on the recommended approach.

@aikithoughts
Copy link
Contributor

Closing as this topic, https://angular.io/guide/observables talks a great deal about unsubscribing. In addition, observables in general are documented in the official RxJS documentation: https://rxjs.dev/guide/subscription

@aikithoughts aikithoughts self-assigned this May 26, 2021
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests