Bird
0
0

Which of the following is the correct syntax to implement the OnDestroy lifecycle hook in an Angular component?

easy📝 Syntax Q12 of 15
Angular - Components
Which of the following is the correct syntax to implement the OnDestroy lifecycle hook in an Angular component?
Aclass MyComponent implements OnDestroy { ngDestroy() { } }
Bclass MyComponent implements OnDestroy { ngOnDestroy() { } }
Cclass MyComponent { onDestroy() { } }
Dclass MyComponent implements OnDestroy { destroy() { } }
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct method name

    The lifecycle hook method for destruction is ngOnDestroy().
  2. Step 2: Check interface implementation

    Implementing OnDestroy requires defining ngOnDestroy() exactly.
  3. Final Answer:

    class MyComponent implements OnDestroy { ngOnDestroy() { } } -> Option B
  4. Quick Check:

    OnDestroy method = ngOnDestroy() [OK]
Quick Trick: Method name must be ngOnDestroy() exactly [OK]
Common Mistakes:
  • Using wrong method name like ngDestroy or destroy
  • Not implementing the interface
  • Omitting parentheses in method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes