What are Form Controls in Angular

πŸ’‘ Concept Name

FormControl – A class in Angular used to track the value and validation status of an individual form input element within reactive forms.

πŸ“˜ Quick Intro

Form controls represent the basic building blocks of forms in Angular. Each input field is represented by a FormControl that stores the current value, validation state, and interaction status.

🧠 Analogy / Short Story

Think of a FormControl like a digital sensor on a thermostat. It constantly monitors the temperature (input value), checks whether it's within the acceptable range (valid), and reports changes to the central system (form group).

πŸ”§ Technical Explanation

  • πŸ› οΈ A FormControl manages a single input field.
  • 🎯 Tracks user input value in real-time.
  • πŸ“‹ Maintains validation status (valid, invalid, pending).
  • πŸ“¦ Part of FormGroup or used standalone.
  • πŸ’‘ Exposes properties like .value, .valid, .touched, and .errors.
  • βœ… Used with built-in or custom validators.

🎯 Purpose & Use Case

  • βœ… Build reactive forms with control over each input field.
  • βœ… Enable dynamic validation and form logic.
  • βœ… Monitor and respond to form changes programmatically.

πŸ’» Real Code Example

// Create a FormControl with default value and validator
import { FormControl, Validators } from '@angular/forms';

usernameControl = new FormControl('', Validators.required);

// Access value and validation status
console.log(this.usernameControl.value);       // ""
console.log(this.usernameControl.valid);       // false
console.log(this.usernameControl.errors);      // { required: true }

❓ Interview Q&A

Q1: What is a FormControl in Angular?
A: It’s a class used to manage the value and validation status of an individual input in a reactive form.

Q2: What are key properties of FormControl?
A: value, valid, errors, touched, dirty.

Q3: How do you validate a FormControl?
A: By passing Angular validators like Validators.required during initialization.

Q4: Can FormControl exist without FormGroup?
A: Yes, it can be used standalone.

Q5: How do you check if a control is touched?
A: Use the .touched property of FormControl.

πŸ“ MCQs

Q1. Which class is used to manage input fields in Angular Reactive Forms?

  • NgModel
  • FormControl
  • FormArray
  • TemplateControl

Q2. What property checks if the form control is valid?

  • touched
  • value
  • valid
  • dirty

Q3. Which module is required for using FormControl?

  • FormsModule
  • ReactiveFormsModule
  • HttpClientModule
  • CommonModule

Q4. What does FormControl track?

  • HTML structure
  • Only input value
  • Styling
  • Value and validation status

Q5. How to apply a required validator?

  • required()
  • isRequired()
  • Validators.required
  • requiredValidator()

Q6. Can you use FormControl outside FormGroup?

  • No
  • Yes
  • Only in ngForm
  • Only with ViewChild

Q7. What property tells if the control has been interacted with?

  • dirty
  • touched
  • invalid
  • pristine

Q8. Which Angular feature reacts to real-time input change?

  • NgModel
  • FormBuilder
  • FormControl
  • ControlGroup

Q9. How do you read errors from FormControl?

  • .isValid
  • .errors
  • .status
  • .getError()

Q10. What type of form approach is FormControl part of?

  • Template Forms
  • Reactive Forms
  • Dynamic Forms
  • Component Forms

πŸ’‘ Bonus Insight

You can subscribe to valueChanges on a FormControl to reactively monitor input updates and use debounceTime to optimize real-time search features.

πŸ“„ PDF Download

Need a handy summary for your notes? Download this topic as a PDF!

πŸ’¬ Feedback
πŸš€ Start Learning
Share:

Tags: