What should you do to ensure that an HTTP request is unsubscribed automatically when a component is destroyed?

  • Automatically unsubscribed by default
  • Manually unsubscribe in the ngOnDestroy lifecycle hook
  • Use the async pipe
  • Use the takeUntil() operator with a subject
To ensure that an HTTP request is unsubscribed automatically when a component is destroyed, you should use the 'takeUntil()' operator with a subject. This pattern helps prevent memory leaks by unsubscribing from observable streams when the component is no longer in use.
Add your answer
Loading...

Leave a comment

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