Complete the code to import the correct Angular form module.
import { [1] } from '@angular/forms';
The ReactiveFormsModule is needed to work with reactive forms and track form state like dirty, touched, and valid.
Complete the code to create a new form control with an initial empty value.
const nameControl = new FormControl([1]);Using an empty string '' initializes the form control with no text, which is common for text inputs.
Fix the error in checking if the form control has been touched.
if (this.form.get('email')?.[1]) { console.log('Email touched'); }
The touched property tells if the user has focused and then left the input, which is what we want to check here.
Fill both blanks to create a form group with a required validator and check if it is valid.
this.form = new FormGroup({
username: new FormControl('', [1])
});
const isValid = this.form.get('username')?.[2];Use Validators.required to make the username mandatory, and check the valid property to see if the input passes validation.
Fill all three blanks to mark the form control as touched, check if it is dirty, and reset the form.
const control = this.form.get('password'); control?.[1](); const isDirty = control?.[2]; this.form.[3]();
Use markAsTouched() to mark the control as touched, check the dirty property to see if it was changed, and call reset() on the form to clear all controls.