Complete the code to import the FormsModule needed for template-driven forms in Angular.
import { [1] } from '@angular/forms';
The FormsModule is required to use template-driven forms in Angular.
Complete the code to bind the input field to the component property using two-way binding.
<input [(ngModel)]="[1]" name="username">
name attributeThe property username is bound to the input using [(ngModel)] for two-way binding.
Fix the error in the form submission method to prevent default behavior.
<form (ngSubmit)="[1]($event)">
The method onSubmit is commonly used to handle form submission and can receive the event to prevent default behavior.
Fill both blanks to create a reactive form control and bind it in the template.
this.form = new FormGroup({ name: new [1]('') });
<input [formControl]="this.form.get('[2]')">FormControl creates a control for the form field, and the control is accessed by its name name in the template.
Fill all three blanks to add validation and check if the form control is valid.
this.form = new FormGroup({
email: new FormControl('', [[1].required, [2].email])
});
const isValid = this.form.get('email')?.[3];Validators provides built-in validation functions like required and email. The valid property checks if the control passes validation.