Bird
0
0

Why is it important to implement ngOnDestroy even if Angular destroys the component automatically?

hard📝 Conceptual Q10 of 15
Angular - Lifecycle Hooks
Why is it important to implement ngOnDestroy even if Angular destroys the component automatically?
ABecause ngOnDestroy is required to render the component
BBecause ngOnDestroy improves component initialization speed
CBecause Angular does not automatically clean up subscriptions or timers
DBecause Angular uses ngOnDestroy to reload data
Step-by-Step Solution
Solution:
  1. Step 1: Understand Angular component destruction

    Angular removes the component from the DOM automatically but does not clean up resources like subscriptions or timers.
  2. Step 2: Recognize ngOnDestroy role

    ngOnDestroy is the place to manually clean these resources to prevent memory leaks.
  3. Final Answer:

    Because Angular does not automatically clean up subscriptions or timers -> Option C
  4. Quick Check:

    Angular auto-destroys but manual cleanup needed [OK]
Quick Trick: Angular destroys component but you clean resources in ngOnDestroy [OK]
Common Mistakes:
  • Assuming Angular cleans subscriptions automatically
  • Thinking ngOnDestroy affects rendering
  • Believing ngOnDestroy reloads data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes