Problem Statement
Give a practical use for ngOnChanges, ngOnInit, and ngOnDestroy.
Explanation
Use ngOnChanges to react to @Input changes (e.g., refresh filtered data). Use ngOnInit for one-time setup like fetching initial data or wiring subscriptions. Use ngOnDestroy to clean up: unsubscribe, remove timers, and detach listeners to avoid memory leaks.
Code Solution
SolutionRead Only
ngOnDestroy(){ this.sub?.unsubscribe(); clearTimeout(this.tid); }