Bird
0
0

When is the ngOnInit method called during the Angular component lifecycle?

easy📝 Conceptual Q2 of 15
Angular - Lifecycle Hooks
When is the ngOnInit method called during the Angular component lifecycle?
AAfter the component is destroyed
BAfter the constructor and after input properties are set
CBefore the constructor
DBefore input properties are set
Step-by-Step Solution
Solution:
  1. Step 1: Recall Angular lifecycle order

    The constructor runs first, then Angular sets input properties, then calls ngOnInit.
  2. Step 2: Confirm timing of ngOnInit

    ngOnInit runs once after inputs are ready, before rendering.
  3. Final Answer:

    After the constructor and after input properties are set -> Option B
  4. Quick Check:

    ngOnInit timing = after constructor and inputs [OK]
Quick Trick: ngOnInit runs after constructor and inputs set [OK]
Common Mistakes:
  • Thinking ngOnInit runs before constructor
  • Assuming ngOnInit runs multiple times
  • Confusing ngOnInit with ngOnDestroy

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes