Bird
0
0

Which of the following is the correct syntax for implementing ngOnChanges in an Angular component?

easy📝 Syntax Q3 of 15
Angular - Lifecycle Hooks
Which of the following is the correct syntax for implementing ngOnChanges in an Angular component?
AngOnChanges(): void { }
BngOnChanges(changes: any): string { }
CngOnChanges(changes: string[]): void { }
DngOnChanges(changes: SimpleChanges): void { }
Step-by-Step Solution
Solution:
  1. Step 1: Recall the method signature

    ngOnChanges expects a parameter of type SimpleChanges and returns void.

  2. Step 2: Check each option's correctness

    ngOnChanges(changes: SimpleChanges): void { } matches the correct signature. Others have wrong parameter types or return types.

  3. Final Answer:

    ngOnChanges(changes: SimpleChanges): void { } -> Option D
  4. Quick Check:

    Correct ngOnChanges syntax [OK]
Quick Trick: Use SimpleChanges type and void return for ngOnChanges [OK]
Common Mistakes:
  • Omitting the parameter
  • Using wrong parameter types
  • Returning a non-void type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes