Fundamental objects of model-driven forms

FormControl and FormGroup are the two fundamental objects in a model-driven form. FormControl is an input field in the Angular form that encapsulates the value of the input field, its state (is valid), if it has changed (is dirty), or has any errors.

When we build a form, we need to create controls and attach metadata to the controls. We have to attach the Control class to the DOM input element by adding the formControlName attribute, as shown:

<input type="text" formControlName="name" />

FormGroup can be instantiated by FormBuilder. We can also manually construct FormGroup in the components with the default values, as illustrated:

this.bookForm = new FormGroup({ name: new FormControl('book name', ...

Get Learning Angular for .NET Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.