Angular - Lifecycle HooksWhy is it important to implement ngOnDestroy in components that subscribe to observables?ATo automatically refresh data when component is destroyedBTo prevent memory leaks by unsubscribing when component is destroyedCTo delay component destruction until subscriptions completeDTo restart subscriptions after component destructionCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand subscription lifecycleSubscriptions keep resources active; if not unsubscribed, they cause memory leaks.Step 2: Role of ngOnDestroyngOnDestroy is used to unsubscribe from observables to free resources when component is destroyed.Final Answer:To prevent memory leaks by unsubscribing when component is destroyed -> Option BQuick Check:Unsubscribe in ngOnDestroy to avoid leaks [OK]Quick Trick: Unsubscribe in ngOnDestroy to prevent leaks [OK]Common Mistakes:Ignoring unsubscription causing memory leaksThinking ngOnDestroy refreshes or restarts subscriptions
Master "Lifecycle Hooks" in Angular9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Angular Quizzes Angular Fundamentals - How Angular differs from React and Vue - Quiz 13medium Angular Fundamentals - What is Angular - Quiz 12easy Angular Fundamentals - Why Angular for enterprise applications - Quiz 5medium Angular Modules - Module lazy loading preview - Quiz 8hard Component Interaction - ng-content for slot-based composition - Quiz 4medium Components - Why components are the building blocks - Quiz 2easy Directives - *ngFor for list rendering - Quiz 11easy Lifecycle Hooks - ngOnDestroy for cleanup - Quiz 13medium Pipes - Creating custom pipes - Quiz 7medium TypeScript in Angular - Generics in Angular services - Quiz 12easy