Bird
0
0

What will happen if you try to access an @Input property inside the constructor instead of ngOnInit?

medium📝 Predict Output Q5 of 15
Angular - Lifecycle Hooks
What will happen if you try to access an @Input property inside the constructor instead of ngOnInit?
AThe @Input property will always have the correct value
BThe @Input property may be undefined or not yet set
CAngular throws a compile-time error
DThe component will not render
Step-by-Step Solution
Solution:
  1. Step 1: Understand @Input timing

    @Input properties are set after the constructor runs, before ngOnInit.
  2. Step 2: Accessing @Input in constructor

    Accessing @Input in constructor may get undefined or default value because Angular hasn't set it yet.
  3. Final Answer:

    The @Input property may be undefined or not yet set -> Option B
  4. Quick Check:

    @Input ready after constructor, safe in ngOnInit [OK]
Quick Trick: Access @Input only in ngOnInit or later [OK]
Common Mistakes:
  • Expecting @Input to be ready in constructor
  • Assuming Angular throws error for early access
  • Confusing compile-time and runtime behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes