Bundling controls with a FormGroup

Naturally, forms in applications frequently exist to aggregate multiple instances of input into a unified behavior. One common behavior is to assess whether a form is valid, which of course requires that all of its subfields are valid. This will most commonly be achieved by bundling multiple FormControl objects into a FormGroup. This can be done in different ways, with varying degrees of explicitness. This recipe covers an entirely explicit implementation, that is, everything here will be created and "joined" manually.

Note

The code, links, and a live example related to this recipe are available at http://ngcookbook.herokuapp.com/3052.

Getting ready

Suppose you began with the following skeleton application:

[app/article-editor.component.ts] ...

Get Angular 2 Cookbook 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.