Angular Forms
Angular Forms Interview with follow-up questions
1. What are the two types of forms that Angular supports?
Angular supports template-driven forms and reactive (model-driven) forms.
- Template-driven (
FormsModule) — the form model is built implicitly from directives in the template (ngModel,ngForm). Quick for simple forms, but logic lives in the template and is harder to test. - Reactive (
ReactiveFormsModule) — you define the model explicitly in the class (FormControl/FormGroup/FormArray), bound with[formGroup]/formControlName. More boilerplate, but typed, synchronous, dynamic, and easily unit-tested — the default choice for non-trivial forms.
The 2026 follow-up to be ready for: Angular is introducing signal-based forms (stabilizing in v22), a third, reactive-by-signals approach. So a current answer is "two established approaches — template-driven and reactive, with reactive preferred — and a new signal-based forms API arriving."
Follow-up 1
What are the key differences between template-driven and reactive forms?
Template-driven forms are based on Angular's template syntax and are easier to use for simple forms. Reactive forms, on the other hand, are more flexible and powerful, allowing for complex form scenarios and dynamic form controls.
Follow-up 2
When would you use one type of form over the other?
You would use template-driven forms when you have simple forms with basic validation requirements and want to take advantage of Angular's template syntax. Reactive forms are recommended for complex forms with advanced validation, dynamic form controls, and the need for more control over form behavior.
Follow-up 3
Can you explain how to implement validation in both types of forms?
In template-driven forms, you can implement validation by adding directives such as ngModel and ngModelGroup to form controls and using built-in validators or custom validators. In reactive forms, you can implement validation by defining form controls and validators programmatically using the FormBuilder class, and then subscribing to value changes and form status changes to perform validation checks.
2. How do you track the state and validity of a form or form control in Angular?
Every AbstractControl (a FormControl, FormGroup, or FormArray) exposes state flags you can read in the class or template:
- Validity:
valid/invalid, plusstatus(VALID,INVALID,PENDING,DISABLED) and theerrorsobject. - Interaction:
touched/untouched(blurred or not),dirty/pristine(value changed or not). - Value:
value, and the observablevalueChanges/statusChangesstreams.
@if (form.controls.email.invalid && form.controls.email.touched) {
<small>Enter a valid email</small>
}
These flags also surface as CSS classes on the elements (ng-valid, ng-invalid, ng-touched, ng-dirty), which is how you style error states. A common best practice to mention: gate error messages on touched/dirty so you don't flag fields the user hasn't interacted with yet. (And with the upcoming signal-based forms, this state is exposed as signals you read directly.)
Follow-up 1
What are the different states a form control can be in?
A form control in Angular can be in the following states:
VALID: The form control has passed all the validation checks.INVALID: The form control has failed one or more validation checks.PENDING: The form control is in the process of being validated.DISABLED: The form control is disabled and cannot be interacted with.
These states can be accessed using the status property of the FormControl instance.
Follow-up 2
How can you display different validation error messages based on the state of a form control?
In Angular, you can display different validation error messages based on the state of a form control by using the errors property of the FormControl instance. The errors property is an object that contains the validation errors for the form control.
You can check for specific validation errors using the hasError method of the FormControl instance. For example, if you want to display a specific error message when the form control is invalid and has the required error, you can use the following code:
<div>
This field is required.
</div>
Follow-up 3
Can you explain how to use the updateOn option to control when validations are run?
In Angular, you can use the updateOn option to control when validations are run for a form control. The updateOn option can be set to one of the following values:
change: The form control is validated whenever its value changes.blur: The form control is validated when it loses focus.submit: The form control is validated when the form is submitted.
By default, the updateOn option is set to change. To change the update behavior, you can pass the updateOn option as a second parameter to the FormControl constructor or use the setValidators method of the FormControl instance.
For example, to set the update behavior to blur, you can use the following code:
const myFormControl = new FormControl('', { updateOn: 'blur' });
3. What is the purpose of the FormGroup and FormControl classes in Angular?
They're the building blocks of reactive forms:
FormControl— tracks the value and validation state of a single field (input, select, checkbox).FormGroup— a keyed collection of controls treated as one unit; its value is an object, and it's valid only if all children are valid.- (Worth naming too:
FormArrayfor a dynamic list of controls.)
form = new FormGroup({
email: new FormControl('', [Validators.required, Validators.email]),
password: new FormControl('', Validators.required),
});
// form.value -> { email, password }
Together they give you a single source of truth for the form's value, validity, and state, plus observable valueChanges/statusChanges streams. A current note: since v14 these are strictly typed (FormControl), so form.value is fully typed — and Angular's new signal-based forms build on the same concepts with a signal-native API.
Follow-up 1
How do you create a FormGroup or FormControl?
To create a FormGroup or FormControl, you need to import the necessary classes from the @angular/forms module. Here's an example of how to create a FormGroup and FormControl in Angular:
import { FormGroup, FormControl } from '@angular/forms';
// Create a new FormGroup
const myFormGroup = new FormGroup({
username: new FormControl(''),
password: new FormControl('')
});
// Create a new FormControl
const myFormControl = new FormControl('');
Follow-up 2
What is the difference between a FormGroup and a FormControl?
The main difference between a FormGroup and a FormControl is that a FormGroup represents a collection of form controls, while a FormControl represents an individual form control. FormGroup is used to group related form controls together, while FormControl is used to represent a single form control. FormGroup provides methods for managing the collection of form controls, such as adding or removing controls, while FormControl provides methods for managing the state and value of a single form control.
Follow-up 3
Can you explain how to use these classes to create a nested form group?
Yes, you can use the FormGroup and FormControl classes to create a nested form group. Here's an example:
import { FormGroup, FormControl } from '@angular/forms';
// Create a nested form group
const addressFormGroup = new FormGroup({
street: new FormControl(''),
city: new FormControl(''),
state: new FormControl('')
});
const myFormGroup = new FormGroup({
username: new FormControl(''),
password: new FormControl(''),
address: addressFormGroup
});
4. How do you handle form submission in Angular?
Bind the form's (ngSubmit) event to a handler method — Angular fires it when a type="submit" button is pressed (and prevents the default full-page reload).
Save
onSubmit() {
if (this.form.invalid) { this.form.markAllAsTouched(); return; }
this.api.save(this.form.value).subscribe(/* … */);
}
The details interviewers reward: prefer (ngSubmit) over a button (click) so keyboard "Enter" submission works; guard on validity and call markAllAsTouched() to reveal error messages; and read the typed form.getRawValue() if you need disabled-control values too. Use [disabled]="form.invalid" to prevent premature submits.
Follow-up 1
What happens if you try to submit a form that is invalid?
If you try to submit a form that is invalid, Angular will prevent the default form submission behavior. It will also mark the invalid form controls as 'touched' and 'dirty', which will trigger any validation error messages to be displayed. This allows you to provide feedback to the user and prevent them from submitting the form until it is valid.
Follow-up 2
How can you prevent the default form submission behavior?
To prevent the default form submission behavior in Angular, you can use the event.preventDefault() method. This method can be called in the method that handles the form submission, which is bound to the ngSubmit event. By calling event.preventDefault(), you can stop the form from being submitted and perform any custom actions instead.
Follow-up 3
Can you explain how to use the ngSubmit event to handle form submissions?
To use the ngSubmit event to handle form submissions in Angular, you need to do the following:
- Add the (ngSubmit) attribute to the form element in your template and bind it to a method in your component.
Submit
- Implement the onSubmit() method in your component. This method will be called when the form is submitted.
onSubmit() {
// form submission logic
}
Inside the onSubmit() method, you can access the form data using the Angular Forms API and perform any necessary actions, such as sending the data to a server or updating the state of your application.
5. What is the role of the FormBuilder service in Angular?
FormBuilder is an injectable helper that reduces the boilerplate of building reactive forms — instead of new FormGroup({ ... new FormControl() }), you write concise object/array literals:
private fb = inject(FormBuilder);
form = this.fb.group({
email: ['', [Validators.required, Validators.email]],
password: ['', Validators.required],
address: this.fb.group({ city: [''], zip: [''] }),
});
Each [initialValue, validators, asyncValidators] tuple becomes a FormControl, and nested fb.group/fb.array build the tree.
A current note interviewers like: prefer NonNullableFormBuilder (or fb.nonNullable) so controls reset to their initial value instead of null and types stay non-nullable. FormBuilder is purely ergonomic — it produces the same FormGroup/FormControl instances you'd create manually, just more readably.
Follow-up 1
How does FormBuilder simplify the process of creating forms?
FormBuilder simplifies the process of creating forms by providing a declarative way to define form controls and their validators. It allows you to define form controls using a builder pattern, which makes it easier to read and maintain the code. FormBuilder also provides convenient methods for adding validators, setting default values, and handling form events.
Follow-up 2
Can you show an example of how to use FormBuilder to create a form?
Sure! Here's an example of how to use FormBuilder to create a simple login form:
import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
@Component({
selector: 'app-login-form',
templateUrl: './login-form.component.html',
styleUrls: ['./login-form.component.css']
})
export class LoginFormComponent {
loginForm: FormGroup;
constructor(private formBuilder: FormBuilder) {
this.loginForm = this.formBuilder.group({
username: ['', Validators.required],
password: ['', Validators.required]
});
}
onSubmit() {
if (this.loginForm.valid) {
// Perform login logic
}
}
}
In this example, we use the FormBuilder service to create a FormGroup instance called loginForm. We define two form controls, username and password, with their respective validators. The form controls are then bound to input fields in the template using the formControlName directive.
Follow-up 3
What are the advantages and disadvantages of using FormBuilder?
Advantages of using FormBuilder:
- Simplifies the process of creating and managing forms
- Provides a declarative way to define form controls and their validators
- Offers convenient methods for adding validators, setting default values, and handling form events
Disadvantages of using FormBuilder:
- Requires additional code and dependencies
- May have a learning curve for developers new to Angular forms
- May not be suitable for simple forms with few form controls, as it adds some overhead
Live mock interview
Mock interview: Angular Forms
- Read your scene and goals
- Talk it out; goals tick off live
- Get a score and stronger lines
Your voice and your AI key never touch our servers; the key stays in this browser and is sent only to Google. Only your round scores are saved to track progress.