Forms are basically part of every application nowadays. It doesn't matter which technology you are working on, at some point, you will need to create forms.
Forms are a container of your controls or we can say they are used for gathering the data from the user, the user provides values to the controls.
Angular also provides the same functionality for forms but in the case of Angular, we have 2 types of forms,
- Template driven form
- Reactive form
There are lots of differences between reactive and template driven form but the main is: Reactive forms are synchronous while Template-driven forms are asynchronous.
This blog is about how to use Template-Driven to create a simple user registration form.
So let us start with Template-Driven form.
- A template driven form allows you to use HTML controls and bind their property with a model using ngModel directive.
- ngModel is provided by Angular and its purpose is to bind model property with the control and can be used for achieving 2-way bindings. I will explain 2-way binding later.
Create a component and name it as User Registration. Once it gets created, copy the data from below and paste it in User Registration component HTML.
- <form #form="ngForm" (ngSubmit)="register(form.value)">
- <label>Firstname:</label>
- <inputtype="text"name="firstname"ngModel="firstname">
- <label>Lastname:</label>
- <inputtype="text"name="lastname"ngModel>
- <label>Street:</label>
- <inputtype="text"name="street"ngModel= "street">
- <label>Zip:</label>
- <inputtype="text"name="zip"ngModel>
- <label>City:</label>
- <inputtype="text"name="city"ngModel>
- <buttontype="submit">Submit</button>
- </form>

Join the conversation! Your thoughts help the community grow.