Bird
0
0

Why does Angular call ngOnChanges before ngOnInit when a component has input properties?

hard📝 Conceptual Q10 of 15
Angular - Components
Why does Angular call ngOnChanges before ngOnInit when a component has input properties?
ABecause ngOnInit depends on ngAfterViewInit to complete first
BTo provide the component with the initial input property values before initialization
CTo delay initialization until all child components are ready
DBecause ngOnChanges is only called once after the component is destroyed
Step-by-Step Solution
Solution:
  1. Step 1: Understand input property flow

    Angular sets input properties and calls ngOnChanges to notify the component of changes.
  2. Step 2: Initialization order

    ngOnChanges runs before ngOnInit to ensure the component has the latest input values before initialization.
  3. Final Answer:

    To provide the component with the initial input property values before initialization -> Option B
  4. Quick Check:

    ngOnChanges runs first to update inputs [OK]
Quick Trick: ngOnChanges runs first to update inputs [OK]
Common Mistakes:
  • Thinking ngOnInit runs first
  • Confusing with view hooks
  • Misunderstanding ngOnChanges timing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes