Bird
0
0

Which Angular lifecycle hook is best suited to perform unsubscription from Observables?

easy🧠 Conceptual Q2 of 15
Angular - RxJS and Observables Fundamentals
Which Angular lifecycle hook is best suited to perform unsubscription from Observables?
AngAfterViewInit
BngOnInit
CngOnDestroy
DngDoCheck
Step-by-Step Solution
Solution:
  1. Step 1: Identify lifecycle hooks purpose

    ngOnDestroy is called just before the component is removed from the DOM.
  2. Step 2: Match unsubscription timing

    Unsubscribing should happen when component is about to be destroyed to free resources.
  3. Final Answer:

    ngOnDestroy -> Option C
  4. Quick Check:

    Unsubscribe in ngOnDestroy = C [OK]
Quick Trick: Use ngOnDestroy to clean up subscriptions [OK]
Common Mistakes:
MISTAKES
  • Trying to unsubscribe in ngOnInit
  • Using ngAfterViewInit for unsubscription
  • Confusing ngDoCheck with cleanup hook

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes