Bird
0
0

Which of the following is the correct way to implement ngOnDestroy in an Angular component?

easy📝 Syntax Q12 of 15
Angular - Lifecycle Hooks
Which of the following is the correct way to implement ngOnDestroy in an Angular component?
Adestroy() { console.log('Component destroyed'); }
BngOnDestroy = () => { console.log('Component destroyed'); }
Cfunction ngOnDestroy() { console.log('Component destroyed'); }
DngOnDestroy() { console.log('Component destroyed'); }
Step-by-Step Solution
Solution:
  1. Step 1: Recall Angular lifecycle hook syntax

    Angular lifecycle hooks are methods inside the component class with exact names like ngOnDestroy().
  2. Step 2: Check method declaration style

    The correct syntax is a method, not an arrow function or standalone function, and must be named exactly ngOnDestroy.
  3. Final Answer:

    ngOnDestroy() { console.log('Component destroyed'); } -> Option D
  4. Quick Check:

    ngOnDestroy method syntax = ngOnDestroy() { console.log('Component destroyed'); } [OK]
Quick Trick: Use method syntax named exactly ngOnDestroy [OK]
Common Mistakes:
  • Using arrow functions for lifecycle hooks
  • Naming method incorrectly
  • Defining lifecycle hook outside class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes