Angular

Reactive Forms

ReactiveFormsModule, FormControl, FormGroup, FormArray, FormBuilder, validators, custom validators, async validators, valueChanges

26 interview questionsยท
Mid-Level
1

What is a FormControl in Angular?

Answer

FormControl is the fundamental class of Angular reactive forms that represents an individual form field. It encapsulates the field's value, validation state, and provides methods to handle user interactions. Each FormControl can have validators, react to changes via observables, and maintain states like touched, dirty, or pristine. It's the basic building block for constructing complex reactive forms with FormGroup or FormArray.

2

Which Angular module must be imported to use reactive forms?

Answer

ReactiveFormsModule is the Angular module that provides all the classes and directives needed to work with reactive forms. It must be imported in the application module or in a standalone component to access FormControl, FormGroup, FormBuilder and other APIs. Without this import, directives like formControlName or formGroup won't be recognized. FormsModule is a different module used for template-driven forms.

3

What is a FormGroup in Angular?

Answer

FormGroup is a class that groups multiple FormControl or other FormGroup instances under named keys, allowing complex forms to be structured. It enables validating and managing the state of a set of fields as a single unit. For example, an address form can be a FormGroup containing street, city, and postal code fields. FormGroup automatically aggregates the values and validation states of all its child controls.

4

What is the purpose of FormBuilder in Angular?

5

How to create a FormControl with an initial value?

+23 interview questions

Master Angular for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free