You have a component that fetches and displays user data. You want to ensure that if the component is destroyed, the subscription to the Observable fetching the data is also terminated. How would you achieve this?

  • Manually unsubscribing in ngOnDestroy()
  • Using a takeUntil() operator with ngOnDestroy()
  • Using a timeout operator with RxJS complete()
  • Using async pipe with RxJS finalize() operator
To ensure the subscription is terminated when the component is destroyed, you can use the takeUntil() operator in combination with ngOnDestroy(). This allows you to unsubscribe when the component's lifecycle ends, preventing memory leaks.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *