Angular · Junior · Question 35 of 75
When is ngOnDestroy called?
- ✓Correct answer: Right before Angular removes the component, for example when an
@ifbecomes false or the route changes - 2After every change detection run
- 3When the browser tab is closed
Explanation
Use it (or DestroyRef.onDestroy) to stop timers, unsubscribe from long-lived Observables and detach listeners. Otherwise they keep running and leak memory.