A form is a container of your controls or we can say, it is used for gathering the data from the user; the user provides values to the controls.
Angular provides 2 types of forms which can be used to declare and define controls at the form level.
- Template driven
- Reactive Form
We have already discussed Template driven forms. You can find the article here.
The purpose of the Reactive form is same as Template driven form. The only difference is that we create controls at run time. There are a few concepts which we need to take care of in case of Reactive forms.
Form Group
Form group is a class which is used to create a form model for your application. It is a collection of Form Control or we can say that it contains form control which will be rendered on the browser.
It is available in - @angular/forms
Form Control
Form controls are basically controls (html , etc.) which will bind to the form group and get rendered on the browser. Or we can say they are the smallest units of a template just like a leaf of a tree.
To understand how form group & form controls work, let's create a simple application using Reactive Form.
Create a component and name it anything. Here, we name it Contact. Use "ng g c componentName" to create the new component.
Add the following code to contact.component.ts and add form group & form control directives available in @angular/forms.
- countries = ['USA', 'Germany', 'Italy', 'France'];
- requestTypes = ['Claim', 'Feedback', 'Help Request'];
- contactForm: FormGroup;
- constructor() {
- this.contactForm = this.createFormGroup();
- }
- createFormGroup() {
- returnnewFormGroup({
- personalData: newFormGroup({
- email: newFormControl(),
- mobile: newFormControl(),
- country: newFormControl()
- }),
- requestType: newFormControl(),
- text: newFormControl()
- });
- }


Join the conversation! Your thoughts help the community grow.