D
D
Drovosek012021-04-28 10:31:06
Angular
Drovosek01, 2021-04-28 10:31:06

Why is takeUntil for unsubscribing an Observable better placed at the end of a pipe?

I think many people know about the way to unsubscribe from an Observable subscription, by creating a field of the Subject type (for example, with the name unsubscribe $) and in the Angular component in ngOnDestroy calling the next() and complete() methods for this field, as well as using takeUntil (unsubscribe $) to unsubscribe.

Actually, why does takeUntil(unsubscribe$) need to be used at the end of the list of operators in pipe()?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2021-04-28
@Drovosek01

Because a completed observable can be switched to another one that won't complete.
For the same reason, you need to unsubscribe from http, a one-time request can be switched to another one and you can’t follow it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question