Bird
0
0

Identify the error in this code:

medium📝 Debug Q14 of 15
Angular - Reactive Forms
Identify the error in this code:
const ageControl = new FormControl();
ageControl.setValue;
AsetValue is called without parentheses, so no value is set
BFormControl must have an initial value
CsetValue cannot be used on FormControl
DageControl is not declared properly
Step-by-Step Solution
Solution:
  1. Step 1: Check setValue usage

    The code uses ageControl.setValue without parentheses, so the method is referenced but not called.
  2. Step 2: Understand consequences

    Because setValue is not called, no value is set and no error occurs, but the intended update does not happen.
  3. Final Answer:

    setValue is called without parentheses, so no value is set -> Option A
  4. Quick Check:

    Call setValue() with parentheses to update value [OK]
Quick Trick: Always use parentheses to call setValue() [OK]
Common Mistakes:
MISTAKES
  • Forgetting parentheses when calling methods
  • Thinking FormControl needs initial value
  • Misunderstanding method vs property

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes