Bird
0
0

You have this code:

medium📝 Debug Q6 of 15
Angular - Reactive Forms
You have this code:
this.form = new FormGroup({
name: new FormControl('')
});
console.log(this.form.controls.name.dirty);

But it always logs true even though the user did not change the input. What is the likely cause?
AThe control was never touched by the user
BThe control value was programmatically changed after initialization
CThe form was not initialized properly
DThe dirty property is always true by default
Step-by-Step Solution
Solution:
  1. Step 1: Understand what sets dirty to true

    Dirty becomes true when the control's value changes from its initial value, either by user or code.
  2. Step 2: Identify why dirty is true without user input

    If code changes the control value after creation, dirty becomes true even without user action.
  3. Final Answer:

    The control value was programmatically changed after initialization -> Option B
  4. Quick Check:

    Programmatic value change sets dirty true [OK]
Quick Trick: Programmatic value changes also mark control dirty [OK]
Common Mistakes:
MISTAKES
  • Assuming dirty only changes on user input
  • Thinking dirty is true by default
  • Ignoring programmatic value changes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes