Bird
0
0

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

easy📝 Syntax Q3 of 15
Angular - Lifecycle Hooks
Which of the following is the correct way to implement the ngOnDestroy lifecycle hook in an Angular component?
Adestroy() { console.log('Destroyed'); }
BonDestroy() { console.log('Destroyed'); }
CngOnDestroy() { console.log('Destroyed'); }
DngDestroy() { console.log('Destroyed'); }
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct lifecycle hook method name

    The Angular lifecycle hook for destruction is named exactly ngOnDestroy.
  2. Step 2: Verify method signature

    Method must be named ngOnDestroy with parentheses and body; ngOnDestroy() { console.log('Destroyed'); } matches this exactly.
  3. Final Answer:

    ngOnDestroy() { console.log('Destroyed'); } -> Option C
  4. Quick Check:

    Correct ngOnDestroy syntax = ngOnDestroy() { console.log('Destroyed'); } [OK]
Quick Trick: Use exact hook names like ngOnDestroy() [OK]
Common Mistakes:
  • Misspelling lifecycle hook names
  • Omitting parentheses in method declaration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes