O'Reilly logo

Angular 2 Cookbook by Matt Frisbie

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

Bundling FormControls with a FormArray

You will most likely find that FormGroups are more than capable of serving your needs for the purpose of combining many FormControl objects into one container. However, there is one very common pattern that makes its sister type, the FormArray, extremely useful: variable length cloned inputs.

Note

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

Getting ready

Suppose you had the following skeleton application:

[app/article-editor.component.ts] import {Component} from '@angular/core'; import {FormControl, Validators} from '@angular/forms'; @Component({ selector: 'article-editor', template: ` <p>Tags:</p> <ul> <li *ngFor="let t of tagControls; let ...

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