Template-driven forms use two-way data binding (`[(ngModel)]`) to update the data model in the component as changes are made in the template and vice versa. They are ideal for simple forms and use directives in the HTML template to manage form state and validation.
## Core Directives
Template-driven forms rely on the `FormsModule` which provides these key directives:
-`NgModel`: Reconciles value changes in the form element with the data model (`[(ngModel)]`).
-`NgForm`: Automatically creates a top-level `FormGroup` bound to the `<form>` tag.
-`NgModelGroup`: Creates a nested `FormGroup` bound to a DOM element.
## Setup
First, import `FormsModule` into your component or module.
Use `[(ngModel)]` on input elements. **Every element using `[(ngModel)]` MUST have a `name` attribute.** Angular uses the `name` attribute to register the control with the parent `NgForm`.
1. Use the `(ngSubmit)` event on the `<form>` element.
2. Bind the submit button's disabled state to the overall form validity using the `NgForm` template reference variable (e.g., `[disabled]="!userForm.form.valid"`).
## Resetting the Form
To programmatically reset the form to its pristine state (clearing values and validation flags), use the `reset()` method on the `NgForm` instance.