The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Controlling Rx Subscriptions with Async Pipe and BehaviorSubjects

Controlling Rx Subscriptions with Async Pipe and BehaviorSubjects

2:11
Each time you use the Async Pipe, you create a new subscription to the stream in the template. This can cause undesired behavior especially when network requests are involved. This lesson shows how to use a BehaviorSubject to observe the http stream so that only one request is made even though we still have two Async pipes in the template.
Watch this lesson now
Avatar
egghead.io

Each time you use the Async Pipe, you create a new subscription to the stream in the template. This can cause undesired behavior especially when network requests are involved. This lesson shows how to use a BehaviorSubject to observe the http stream so that only one request is made even though we still have two Async pipes in the template.

Avatar
Christopher Kwiatkowski

Since you are now calling subscribe() on the stream - must we set the Subscription object on a property of the component so that we can invoke unsubscribe() on the Subscription when the Component is destroyed or we navigate away from this route?

In reply to egghead.io
Avatar
Cue

Based on what i found googling , you don't need to unsubscribe when you use async pipe, it does it automatically, but if dont use async you need to unsubscribe.

In reply to Christopher Kwiatkowski
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?