Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
Kevin C. Coram ff1268e129
Add summary of static method approach to main README
il y a 3 ans
.vscode initial commit il y a 4 ans
apps Document static method approach il y a 3 ans
libs Refactor createForm() to provide composible factory methods il y a 3 ans
tools initial commit il y a 4 ans
.editorconfig initial commit il y a 4 ans
.gitignore initial commit il y a 4 ans
.prettierignore initial commit il y a 4 ans
.prettierrc Configure prettier to use trailing commas il y a 4 ans
LICENSE Add MIT License file il y a 4 ans
README.md Add summary of static method approach to main README il y a 3 ans
README_NX.md Rename generated README file il y a 4 ans
angular.json Add fourth approach: Static methods on child components il y a 3 ans
jest.config.js Use Nrwl jest resolver plugin il y a 4 ans
nx.json Add fourth approach: Static methods on child components il y a 3 ans
package-lock.json Additional Jest configuration and dependencies il y a 4 ans
package.json Additional Jest configuration and dependencies il y a 4 ans
tsconfig.json Refactor rename lib/contact-model -> lib/contact il y a 4 ans
tslint.json nx g @nrwl/angular:app parent-form il y a 4 ans

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 management 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.

Parent Component Creates Form; Child Components Define Structure

Another approach is to allow the parent component to maintain control of creating the full Reactive Form, while allowing each child component to define the shape of the form data by means of static factory methods defined within the child component code.

The Static Method application explores this approach.