Bird
0
0

You notice your Angular component's ngOnDestroy method is not called when navigating away. What is the most likely cause?

medium📝 Debug Q14 of 15
Angular - Lifecycle Hooks
You notice your Angular component's ngOnDestroy method is not called when navigating away. What is the most likely cause?
AThe component is never destroyed because it is cached or reused
BYou forgot to implement <code>OnDestroy</code> interface
CYou used <code>ngOnDestroy</code> instead of <code>onDestroy</code>
DAngular does not call <code>ngOnDestroy</code> on navigation
Step-by-Step Solution
Solution:
  1. Step 1: Understand when ngOnDestroy runs

    ngOnDestroy runs when Angular destroys the component instance.
  2. Step 2: Identify why it might not run on navigation

    If the component is cached or reused (e.g., via route reuse strategy), it is not destroyed, so ngOnDestroy won't run.
  3. Final Answer:

    The component is never destroyed because it is cached or reused -> Option A
  4. Quick Check:

    ngOnDestroy runs only on actual destruction [OK]
Quick Trick: ngOnDestroy runs only if component is truly destroyed [OK]
Common Mistakes:
  • Confusing interface implementation with method call
  • Using wrong method name
  • Believing Angular never calls ngOnDestroy on navigation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes