Bird
0
0

Which of the following is the correct syntax to define the ngOnDestroy method in an Angular component?

easy📝 Syntax Q3 of 15
Angular - Lifecycle Hooks
Which of the following is the correct syntax to define the ngOnDestroy method in an Angular component?
AngOnDestroy() => { /* cleanup code here */ }
Bdestroy() { /* cleanup code here */ }
Cfunction ngOnDestroy() { /* cleanup code here */ }
DngOnDestroy(): void { /* cleanup code here */ }
Step-by-Step Solution
Solution:
  1. Step 1: Recall Angular lifecycle method syntax

    Lifecycle hooks are class methods with specific names and signatures.
  2. Step 2: Identify correct method signature for ngOnDestroy

    ngOnDestroy is a method with no parameters and returns void, defined as ngOnDestroy(): void { }.
  3. Final Answer:

    ngOnDestroy(): void { /* cleanup code here */ } -> Option D
  4. Quick Check:

    ngOnDestroy syntax = method with void return [OK]
Quick Trick: Use method syntax with void return for ngOnDestroy [OK]
Common Mistakes:
  • Using arrow function syntax for ngOnDestroy
  • Defining ngOnDestroy as a standalone function
  • Naming method destroy instead of ngOnDestroy

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes