Bird
0
0

Given this code snippet:

medium📝 component behavior Q13 of 15
Angular - Reactive Forms
Given this code snippet:
const nameControl = new FormControl('Alice');
nameControl.setValue('Bob');
console.log(nameControl.value);

What will be logged to the console?
Aundefined
B'Alice'
C'Bob'
DError: setValue is not a function
Step-by-Step Solution
Solution:
  1. Step 1: Understand initial value assignment

    The FormControl is created with initial value 'Alice'.
  2. Step 2: Apply setValue method

    The setValue('Bob') updates the control's value to 'Bob'.
  3. Step 3: Check logged value

    Logging nameControl.value outputs the updated value 'Bob'.
  4. Final Answer:

    'Bob' -> Option C
  5. Quick Check:

    setValue changes value immediately [OK]
Quick Trick: setValue updates FormControl value instantly [OK]
Common Mistakes:
MISTAKES
  • Assuming initial value stays after setValue
  • Thinking setValue is asynchronous
  • Confusing value property with method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes