|Kevin C. Coram cd7644a767||il y a 1 an|
|.vscode||il y a 1 an|
|apps||il y a 1 an|
|libs||il y a 1 an|
|tools||il y a 1 an|
|.editorconfig||il y a 1 an|
|.gitignore||il y a 1 an|
|.prettierignore||il y a 1 an|
|.prettierrc||il y a 1 an|
|LICENSE||il y a 1 an|
|README.md||il y a 1 an|
|README_NX.md||il y a 1 an|
|angular.json||il y a 1 an|
|jest.config.js||il y a 1 an|
|nx.json||il y a 1 an|
|package-lock.json||il y a 1 an|
|package.json||il y a 1 an|
|tsconfig.json||il y a 1 an|
|tslint.json||il y a 1 an|
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.
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.
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.
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.