O'Reilly logo

Learning Angular for .NET Developers by Rajesh Gunasundaram

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required