Angular
There are two main types of form in the Angular framework:
1.Template-driven Form
2.Reactive Form
Template-driven Form
The template-driven form is a form that makes use of the form module and most of the logic is driven by the template. Template-driven form is asynchronous in nature. It follows the approach of two-way binding.
Example of template driven form
<section class="sample-app-content">
<h1>Template-driven Form Example (with bi-directional data binding):</h1>
<form #myForm="ngForm" (ngSubmit)=""text"
[(ngModel)]="user.firstName" required>
</p>
<p>
<label>Password:</label>
<input type="password"
[(ngModel)]="user.password" required>
</p>
<p>
<button type="submit" [disabled]="!myForm.valid">Submit</button>
</p>
</form>
</section>
Advantage of using template-driven form are:-
Reactive Form
Reactive form is a form that makes use of reactive form modules and most of the logic is driven by the typescript code. Reactive form is synchronous in nature.
Example of Reactive form:-
<section class="sample-app-content">
<h1>Reactive Form Example:</h1>
<form [formGroup]="form" (ngSubmit)="onSubmit()">
<p>
<label>First Name:</label>
<input type="text" formControlName="firstName">
</p>
<p>
<label>Password:</label>
<input type="password" formControlName="password">
</p>
<p>
<button type="submit" [disabled]="!form.valid">Submit</button>
</p>
</form>
</section>
Advantage of using reactive form are:
Example:-
import { FormGroup, FormControl, Validators } from '@angular/forms';
cardForm = new FormGroup({
name: new FormControl('', [
Validators.required,
Validators.minLength(3),
Validators.maxLength(5),
]),
});
At Oodles ERP, we provide complete enterprise solutions with a focus on building custom applications for web and mobile platforms. Our end-to-end web application development services enable organizations to efficiently manage their routine business tasks and activities. For more information, contact us at [email protected].