Consider an Angular standalone form with a required input field. The user focuses the input, types a valid value, then blurs the input.
What will be the valid state of the form after these actions?
import { Component } from '@angular/core'; import { FormControl, FormGroup, Validators } from '@angular/forms'; @Component({ selector: 'app-simple-form', standalone: true, template: ` <form [formGroup]="form"> <input formControlName="name" /> </form> ` }) export class SimpleFormComponent { form = new FormGroup({ name: new FormControl('', Validators.required) }); }
Remember that valid depends on validators, not on touched or dirty states.
The valid state reflects whether the form controls pass their validators. Since the input has a non-empty value and the required validator is satisfied, the form is valid regardless of touched or dirty states.
Given an Angular reactive form initialized with default values, what is the dirty state of the form immediately after creation?
import { Component } from '@angular/core'; import { FormControl, FormGroup } from '@angular/forms'; @Component({ selector: 'app-init-form', standalone: true, template: `<form [formGroup]="form"></form>` }) export class InitFormComponent { form = new FormGroup({ email: new FormControl('user@example.com') }); }
Think about what dirty means: user changed the value or not.
The dirty state is false initially because the form's value has not been changed by the user. The form is pristine until a user modifies any control.
In this Angular form, the input loses focus but the form's touched state remains false. What is the most likely cause?
import { Component } from '@angular/core'; import { FormControl, FormGroup, Validators } from '@angular/forms'; @Component({ selector: 'app-debug-form', standalone: true, template: ` <form [formGroup]="form"> <input /> </form> ` }) export class DebugFormComponent { form = new FormGroup({ username: new FormControl('', Validators.required) }); }
Check if Angular can connect the input to the form control properly.
If the input lacks the formControlName directive, Angular does not link it to the form control, so it cannot update the touched state on blur.
Which of the following best describes when Angular marks a form control as dirty?
Think about what user action changes the control's state.
Angular marks a control as dirty only when the user changes its value from the initial one. Programmatic changes do not mark it dirty.
Choose the correct Angular code to conditionally enable a submit button only if the form is valid and dirty.
import { Component } from '@angular/core'; import { FormControl, FormGroup, Validators } from '@angular/forms'; @Component({ selector: 'app-submit-form', standalone: true, template: ` <form [formGroup]="form"> <input formControlName="email" /> <button [disabled]="???">Submit</button> </form> ` }) export class SubmitFormComponent { form = new FormGroup({ email: new FormControl('', [Validators.required, Validators.email]) }); }
The button should be disabled if the form is invalid or not dirty.
The submit button should be disabled when the form is invalid or when the user has not changed any values (not dirty). Option D correctly expresses this logic.