You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
Kevin C. Coram cd7644a767
Refactor createForm() to provide composible factory methods
пре 1 година
.vscode initial commit пре 1 година
apps Document 'own form controls' application пре 1 година
libs Refactor createForm() to provide composible factory methods пре 1 година
tools initial commit пре 1 година
.editorconfig initial commit пре 1 година
.gitignore initial commit пре 1 година
.prettierignore initial commit пре 1 година
.prettierrc Configure prettier to use trailing commas пре 1 година
LICENSE Add MIT License file пре 1 година
README.md Add reference to blog article describing the 'own form controls' pattern пре 1 година
README_NX.md Rename generated README file пре 1 година
angular.json Remove e2e tests пре 1 година
jest.config.js Use Nrwl jest resolver plugin пре 1 година
nx.json Remove e2e tests пре 1 година
package-lock.json Additional Jest configuration and dependencies пре 1 година
package.json Additional Jest configuration and dependencies пре 1 година
tsconfig.json Refactor rename lib/contact-model -> lib/contact пре 1 година
tslint.json nx g @nrwl/angular:app parent-form пре 1 година

README.md

Nested Forms - An exploration of alternatives

The official Angular documentation discussing Reactive Forms shows how one can use groups and arrays to organize a form, and to dynamically add to it. The drawback of the example on that page is that everything is in a single component.

Once a component starts to grow in size and complexity, it becomes desirable to decompose it into multiple smaller components. At this point, there are a number of ways to break up the form into a set of nested form elements.

Project Purpose

This project explores several approaches to implementing nested forms/components. The project is structured using the Nrwl Nx monorepository framework, with shared models and services in a library, and separate applications to explore each approach.

Each application implements a simple contact management form, capturing simple demographics information and a list of postal addresses.

Base Line - The Single component

The Base Line application implements the contact manangement form in a single angular component, directly using the example techniques from the Reactive Forms documentation.

Components Creating Own Form Controls

Searching the Internet for examples of nested forms in Angular shows one popular approach is to have each sub-component be responsible for creating its own form controls. The parent form is passed in as an @Input, and the component adds its components to the form using the addControl(name, control) method. See, for example, Nested Reactive Forms in Angular2.

The Parent Form application explores this approach.

Parent Component Creates Form and Passes Form Controls Into Child Components

Another approach is to allow the outermost, or parent, component create the full Reactive Form. Each child component is given the FormGroup containing the portion of the form that it is responsible for rendering.

The Global Form application explores this approach.