Angular - RxJS and Observables Fundamentals
What is a recommended way to unsubscribe from an observable in an Angular component to avoid memory leaks?
subscribe() and call unsubscribe() in the component's ngOnDestroy() lifecycle hook.unsubscribe() in ngOnDestroy() correctly describes this approach. Call subscribe() again to reset the subscription is incorrect; calling subscribe again creates a new subscription. Use setTimeout() to delay unsubscription is unrelated and ineffective. No need to unsubscribe if observable emits only once is risky; even single emissions can cause leaks if not handled properly.unsubscribe() in ngOnDestroy() -> Option B15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions