diff --git a/aio/content/examples/forms-overview/e2e/src/app.e2e-spec.ts b/aio/content/examples/forms-overview/e2e/src/app.e2e-spec.ts new file mode 100644 index 0000000000000..b15faa2a4c8a5 --- /dev/null +++ b/aio/content/examples/forms-overview/e2e/src/app.e2e-spec.ts @@ -0,0 +1,10 @@ +import { browser, element, by } from 'protractor'; + +describe('Forms Overview Tests', function () { + + beforeEach(function () { + browser.get(''); + }); + +}); + diff --git a/aio/content/examples/forms-overview/example-config.json b/aio/content/examples/forms-overview/example-config.json new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/aio/content/examples/forms-overview/src/app/app.component.css b/aio/content/examples/forms-overview/src/app/app.component.css new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/aio/content/examples/forms-overview/src/app/app.component.html b/aio/content/examples/forms-overview/src/app/app.component.html new file mode 100644 index 0000000000000..a274b28459c93 --- /dev/null +++ b/aio/content/examples/forms-overview/src/app/app.component.html @@ -0,0 +1,10 @@ + +

Forms Overview

+ +

Reactive

+ + + +

Template-Driven

+ + \ No newline at end of file diff --git a/aio/content/examples/forms-overview/src/app/app.component.spec.ts b/aio/content/examples/forms-overview/src/app/app.component.spec.ts new file mode 100644 index 0000000000000..1ab69b01846bc --- /dev/null +++ b/aio/content/examples/forms-overview/src/app/app.component.spec.ts @@ -0,0 +1,31 @@ +import { TestBed, async } from '@angular/core/testing'; +import { AppComponent } from './app.component'; +import { TemplateModule } from './template/template.module'; +import { ReactiveModule } from './reactive/reactive.module'; + +describe('AppComponent', () => { + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ReactiveModule, TemplateModule], + declarations: [ + AppComponent + ], + }).compileComponents(); + })); + + it('should create the app', async(() => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.debugElement.componentInstance; + + expect(app).toBeTruthy(); + })); + + it('should render title in a h1 tag', async(() => { + const fixture = TestBed.createComponent(AppComponent); + fixture.detectChanges(); + + const compiled = fixture.debugElement.nativeElement; + expect(compiled.querySelector('h1').textContent).toContain('Forms Overview'); + })); +}); diff --git a/aio/content/examples/forms-overview/src/app/app.component.ts b/aio/content/examples/forms-overview/src/app/app.component.ts new file mode 100644 index 0000000000000..26f42471ce994 --- /dev/null +++ b/aio/content/examples/forms-overview/src/app/app.component.ts @@ -0,0 +1,10 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.css'] +}) +export class AppComponent { + title = 'forms-intro'; +} diff --git a/aio/content/examples/forms-overview/src/app/app.module.ts b/aio/content/examples/forms-overview/src/app/app.module.ts new file mode 100644 index 0000000000000..fbce0eff3e410 --- /dev/null +++ b/aio/content/examples/forms-overview/src/app/app.module.ts @@ -0,0 +1,19 @@ +import { BrowserModule } from '@angular/platform-browser'; +import { NgModule } from '@angular/core'; + +import { AppComponent } from './app.component'; +import { ReactiveModule } from './reactive/reactive.module'; +import { TemplateModule } from './template/template.module'; + +@NgModule({ + declarations: [ + AppComponent, + ], + imports: [ + BrowserModule, + ReactiveModule, + TemplateModule + ], + bootstrap: [AppComponent] +}) +export class AppModule { } diff --git a/aio/content/examples/forms-overview/src/app/reactive/favorite-color/favorite-color.component.spec.ts b/aio/content/examples/forms-overview/src/app/reactive/favorite-color/favorite-color.component.spec.ts new file mode 100644 index 0000000000000..5b676c08b8b8d --- /dev/null +++ b/aio/content/examples/forms-overview/src/app/reactive/favorite-color/favorite-color.component.spec.ts @@ -0,0 +1,50 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ReactiveFormsModule } from '@angular/forms'; + +import { FavoriteColorComponent } from './favorite-color.component'; +import { createNewEvent } from '../../shared/utils'; + +describe('Favorite Color Component', () => { + let component: FavoriteColorComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ ReactiveFormsModule ], + declarations: [ FavoriteColorComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(FavoriteColorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); + + // #docregion view-to-model + it('should update the value of the input field', () => { + const input = fixture.nativeElement.querySelector('input'); + const event = createNewEvent('input'); + + input.value = 'Red'; + input.dispatchEvent(event); + + expect(fixture.componentInstance.favoriteColorControl.value).toEqual('Red'); + }); + // #enddocregion view-to-model + + // #docregion model-to-view + it('should update the value in the control', () => { + component.favoriteColorControl.setValue('Blue'); + + const input = fixture.nativeElement.querySelector('input'); + + expect(input.value).toBe('Blue'); + }); + // #enddocregion model-to-view +}); diff --git a/aio/content/examples/forms-overview/src/app/reactive/favorite-color/favorite-color.component.ts b/aio/content/examples/forms-overview/src/app/reactive/favorite-color/favorite-color.component.ts new file mode 100644 index 0000000000000..282df4d8dbe51 --- /dev/null +++ b/aio/content/examples/forms-overview/src/app/reactive/favorite-color/favorite-color.component.ts @@ -0,0 +1,12 @@ +import { Component } from '@angular/core'; +import { FormControl } from '@angular/forms'; + +@Component({ + selector: 'app-reactive-favorite-color', + template: ` + Favorite Color: + ` +}) +export class FavoriteColorComponent { + favoriteColorControl = new FormControl(''); +} diff --git a/aio/content/examples/forms-overview/src/app/reactive/reactive.module.spec.ts b/aio/content/examples/forms-overview/src/app/reactive/reactive.module.spec.ts new file mode 100644 index 0000000000000..3add422b837f8 --- /dev/null +++ b/aio/content/examples/forms-overview/src/app/reactive/reactive.module.spec.ts @@ -0,0 +1,13 @@ +import { ReactiveModule } from './reactive.module'; + +describe('ReactiveModule', () => { + let reactiveModule: ReactiveModule; + + beforeEach(() => { + reactiveModule = new ReactiveModule(); + }); + + it('should create an instance', () => { + expect(reactiveModule).toBeTruthy(); + }); +}); diff --git a/aio/content/examples/forms-overview/src/app/reactive/reactive.module.ts b/aio/content/examples/forms-overview/src/app/reactive/reactive.module.ts new file mode 100644 index 0000000000000..3b85430dda23f --- /dev/null +++ b/aio/content/examples/forms-overview/src/app/reactive/reactive.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { ReactiveFormsModule } from '@angular/forms'; +import { FavoriteColorComponent } from './favorite-color/favorite-color.component'; + +@NgModule({ + imports: [ + CommonModule, + ReactiveFormsModule + ], + declarations: [FavoriteColorComponent], + exports: [FavoriteColorComponent], +}) +export class ReactiveModule { } diff --git a/aio/content/examples/forms-overview/src/app/shared/utils.ts b/aio/content/examples/forms-overview/src/app/shared/utils.ts new file mode 100644 index 0000000000000..a7cb3ce69ca42 --- /dev/null +++ b/aio/content/examples/forms-overview/src/app/shared/utils.ts @@ -0,0 +1,5 @@ +export function createNewEvent(eventName: string, bubbles = false, cancelable = false) { + let evt = document.createEvent('CustomEvent'); + evt.initCustomEvent(eventName, bubbles, cancelable, null); + return evt; +} diff --git a/aio/content/examples/forms-overview/src/app/template/favorite-color/favorite-color.component.spec.ts b/aio/content/examples/forms-overview/src/app/template/favorite-color/favorite-color.component.spec.ts new file mode 100644 index 0000000000000..60e1830b4d5e6 --- /dev/null +++ b/aio/content/examples/forms-overview/src/app/template/favorite-color/favorite-color.component.spec.ts @@ -0,0 +1,56 @@ +import { async, ComponentFixture, TestBed, tick, fakeAsync } from '@angular/core/testing'; +import { FormsModule } from '@angular/forms'; + +import { FavoriteColorComponent } from './favorite-color.component'; +import { createNewEvent } from '../../shared/utils'; + +describe('FavoriteColorComponent', () => { + let component: FavoriteColorComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ FormsModule ], + declarations: [ FavoriteColorComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(FavoriteColorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); + + // #docregion model-to-view + it('should update the favorite color on the input field', fakeAsync(() => { + component.favoriteColor = 'Blue'; + + fixture.detectChanges(); + + tick(); + + const input = fixture.nativeElement.querySelector('input'); + + expect(input.value).toBe('Blue'); + })); + // #enddocregion model-to-view + + // #docregion view-to-model + it('should update the favorite color in the component', fakeAsync(() => { + const input = fixture.nativeElement.querySelector('input'); + const event = createNewEvent('input'); + + input.value = 'Red'; + input.dispatchEvent(event); + + fixture.detectChanges(); + + expect(component.favoriteColor).toEqual('Red'); + })); + // #enddocregion view-to-model +}); diff --git a/aio/content/examples/forms-overview/src/app/template/favorite-color/favorite-color.component.ts b/aio/content/examples/forms-overview/src/app/template/favorite-color/favorite-color.component.ts new file mode 100644 index 0000000000000..7a965b7c33c49 --- /dev/null +++ b/aio/content/examples/forms-overview/src/app/template/favorite-color/favorite-color.component.ts @@ -0,0 +1,11 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-template-favorite-color', + template: ` + Favorite Color: + ` +}) +export class FavoriteColorComponent { + favoriteColor = ''; +} diff --git a/aio/content/examples/forms-overview/src/app/template/template.module.spec.ts b/aio/content/examples/forms-overview/src/app/template/template.module.spec.ts new file mode 100644 index 0000000000000..cb28c36acd91e --- /dev/null +++ b/aio/content/examples/forms-overview/src/app/template/template.module.spec.ts @@ -0,0 +1,13 @@ +import { TemplateModule } from './template.module'; + +describe('TemplateModule', () => { + let templateModule: TemplateModule; + + beforeEach(() => { + templateModule = new TemplateModule(); + }); + + it('should create an instance', () => { + expect(templateModule).toBeTruthy(); + }); +}); diff --git a/aio/content/examples/forms-overview/src/app/template/template.module.ts b/aio/content/examples/forms-overview/src/app/template/template.module.ts new file mode 100644 index 0000000000000..dc2ade4f25f5f --- /dev/null +++ b/aio/content/examples/forms-overview/src/app/template/template.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; +import { FavoriteColorComponent } from './favorite-color/favorite-color.component'; + +@NgModule({ + imports: [ + CommonModule, + FormsModule + ], + declarations: [FavoriteColorComponent], + exports: [FavoriteColorComponent] +}) +export class TemplateModule { } diff --git a/aio/content/examples/forms-overview/src/index.html b/aio/content/examples/forms-overview/src/index.html new file mode 100644 index 0000000000000..a4dc0c2ba3a09 --- /dev/null +++ b/aio/content/examples/forms-overview/src/index.html @@ -0,0 +1,14 @@ + + + + + Forms Overview + + + + + + + + + diff --git a/aio/content/examples/forms-overview/src/main.ts b/aio/content/examples/forms-overview/src/main.ts new file mode 100644 index 0000000000000..91ec6da5f0788 --- /dev/null +++ b/aio/content/examples/forms-overview/src/main.ts @@ -0,0 +1,12 @@ +import { enableProdMode } from '@angular/core'; +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; + +import { AppModule } from './app/app.module'; +import { environment } from './environments/environment'; + +if (environment.production) { + enableProdMode(); +} + +platformBrowserDynamic().bootstrapModule(AppModule) + .catch(err => console.log(err)); diff --git a/aio/content/examples/forms-overview/stackblitz.json b/aio/content/examples/forms-overview/stackblitz.json new file mode 100644 index 0000000000000..b3eefdff14b07 --- /dev/null +++ b/aio/content/examples/forms-overview/stackblitz.json @@ -0,0 +1,7 @@ +{ + "description": "Forms Overview", + "files":[ + "!**/*.d.ts", + "!**/*.js" + ] +} diff --git a/aio/content/guide/forms-overview.md b/aio/content/guide/forms-overview.md new file mode 100644 index 0000000000000..975cb0d1024ad --- /dev/null +++ b/aio/content/guide/forms-overview.md @@ -0,0 +1,259 @@ +# Introduction to forms in Angular + +Handling user input with forms is the cornerstone of many common applications. Applications use forms to enable users log in, to update a profile, to enter sensitive information, and to perform many other data-entry tasks. + +Angular provides two different approaches to handling user input through forms: reactive and template-driven. Both capture user input events from the view, validate the user input, create a form model and data model to update, and provide a way to track changes. + +Reactive and template-driven forms differ, however, in how they do the work of processing and managing forms and form data. Each offers different advantages. + +**In general:** + +* **Reactive forms** are more robust: they are more scalable, reusable, and testable. If forms are a key part of your application, or you're already using reactive patterns for building your application, use reactive forms. +* **Template-driven forms** are useful for adding a simple form to an app, such as an email list signup form. They are easy to add to an app, but they do not scale as well as reactive forms. If you have very basic form requirements and logic that can be managed solely in the template, use template-driven forms. + +This guide provides information to help you decide which approach works best for your situation. It introduces the common building blocks used by both approaches. It also summarizes the key differences between the two approaches, and demonstrates those differences in the context of setup, data flow, and testing. + +
+ +*Note:* For complete information about each kind of form, see the [Reactive Forms](guide/reactive-forms) and [Template-driven Forms](guide/forms) guides. + +
+ +## Key differences + +The table below summarizes the key differences between reactive and template-driven forms. + + + +||Reactive|Template-driven| +|--- |--- |--- | +|Setup (form model)|More explicit, created in the component class.|Less explicit, created by the directives.| +|Data model|Structured|Unstructured| +|Predictability|Synchronous|Asynchronous| +|Form validation|Functions|Directives| +|Mutability|Immutable|Mutable| +|Scalability|Low-level API access|Abstraction on top of APIs| + +## Common foundation + +Both reactive and template-driven forms share underlying building blocks. + +- A `FormControl` instance that tracks the value and validation status of an individual form control. +- A `FormGroup` instance that tracks the same values and status for a collection of form controls. +- A `FormArray` instance that tracks the same values and status for an array of form controls. +- A `ControlValueAccessor` that creates a bridge between Angular `FormControl` instances and native DOM elements. + +How these control instances are created and managed with reactive and template-driven forms is introduced in the [form model setup](#setup-the-form-model) section below and detailed further in the [data flow section](#data-flow-in-forms) of this guide. + +## Setup: The form model + +Reactive and template-driven forms both use a form model to track value changes between Angular forms and form input elements. The examples below show how the form model is defined and created. + +### Setup in reactive forms + +Here is a component with an input field for a single control implemented using reactive forms. + + + + +The source of truth provides the value and status of the form element at a given point in time. In reactive forms, the form model is source of truth. The form model in the above example is the `FormControl` instance. + +
+ Reactive forms key differences +
+ +With reactive forms, the form model is explicitly defined in the component class. The reactive form directive (in this case, `FormControlDirective`) then links the existing form control instance to a specific form element in the view using a value accessor (instance of `ControlValueAccessor`). + +### Setup in template-driven forms + +Here is the same component with an input field for a single control implemented using template-driven forms. + + + + +In template-driven forms, the source of truth is the template. + +
+ Template-driven forms key differences +
+ +The abstraction of the form model promotes simplicity over structure. The template-driven form directive `NgModel` is responsible for creating and managing the form control instance for a given form element. It is less explicit, but you no longer have direct control over the form model. + +## Data flow in forms + +When building forms in Angular, it's important to understand how the the framework handles data flowing from the user or from programmatic changes. Reactive and template-driven forms follow two different strategies when handling form input. The data flow examples below begin with the favorite color input field example from above, and they show how changes to favorite color are handled in reactive forms compared to template-driven forms. + +### Data flow in reactive forms + +As described above, in reactive forms each form element in the view is directly linked to a form model (`FormControl` instance). Updates from the view to model and model to view are synchronous and not dependent on the UI rendered. The diagrams below use the same favorite color example to demonstrate how data flows when an input field's value is changed from the view and then from the model. + +
+ Reactive forms data flow - view to model +
+ +The steps below outline the view to model data flow. + +1. The end user types a value into the input element, in this case the favorite color "Blue". +1. The form input element emits an "input" event with the latest value. +1. The control value accessor listening for events on the form input element immediately relays the new value to the `FormControl` instance. +1. The `FormControl` instance emits the new value through the `valueChanges` observable. +1. Any subscribers to the `valueChanges` observable receive the new value. + +
+ Reactive forms data flow - model to view +
+ +The steps below outline the model to view data flow. + +1. The `favoriteColorControl.setValue()` method is called, which updates the `FormControl` value. +1. The `FormControl` instance emits the new value through the `valueChanges` observable. +1. Any subscribers to the `valueChanges` observable receive the new value. +1. The control value accessor on the form input element updates the element with the new value. + +### Data flow in template-driven forms + +In template-driven forms, each form element is linked to a directive that manages the form model internally. The diagrams below uses the same favorite color example to demonstrate how data flows when an input field's value is changed from the view and then from the model. + +
+ Template-driven forms view to model data flow +
+ +The steps below outline the view to model data flow. + +1. The end user types "Blue" into the input element. +1. The input element emits an "input" event with the value "Blue". +1. The control value accessor attached to the input triggers the `setValue()` method on the `FormControl` instance. +1. The `FormControl` instance emits the new value through the `valueChanges` observable. +1. Any subscribers to the `valueChanges` observable receive the new value. +1. The control value accessor also calls the `NgModel.viewToModel()` method which emits an `ngModelChange` event. +1. Because the component template uses two-way data binding for the `favoriteColor`, the `favoriteColor` property in the component +is updated to the value emitted by the `ngModelChange` event ("Blue"). + +
+ Template-driven forms model to view data flow +
+ +The steps below outline the model to view data flow. + +1. The `favoriteColor` value is updated in the component. +1. Change detection begins. +1. During change detection, the `ngOnChanges` lifecycle hook is called on the `NgModel` directive instance because the value of one of its inputs has changed. +1. The `ngOnChanges()` method queues an async task to set the value for the internal `FormControl` instance. +1. Change detection completes. +1. On the next tick, the task to set the `FormControl` instance value is executed. +1. The `FormControl` instance emits the latest value through the `valueChanges` observable. +1. Any subscribers to the `valueChanges` observable receive the new value. +1. The control value accessor updates the form input element in the view with the latest `favoriteColor` value. + +## Form validation + +Validation is an integral part of managing any set of forms. Whether you’re checking for required fields or querying an external API for an existing username, Angular provides a set of built-in validators as well as the ability to create custom validators. + +* **Reactive forms** define custom validators as **functions** that receive a control to validate. +* **Template-driven forms** are tied to template **directives**, and must provide custom validator directives that wrap validation functions. + +For more on form validation, see the [Form Validation](guide/form-validation) guide. + +## Testing + +Testing also plays a large part in complex applications and an easier testing strategy is always welcomed. One difference in testing reactive forms and template-driven forms is their reliance on rendering the UI in order to perform assertions based on form control and form field changes. The following examples demonstrate the process of testing forms with reactive and template-driven forms. + +### Testing reactive forms + +Reactive forms provide a relatively easy testing strategy because they provide synchronous access to the form and data models, and they can be tested without rendering the UI. In these set of tests, controls and data are queried and manipulated through the control without interacting with the change detection cycle. + +The following tests use the favorite color components mentioned earlier to verify the view to model and model to view data flows for a reactive form. + +The following test verifies the view to model data flow: + + + + +The steps performed in the view to model test. + +1. Query the view for the form input element, and create a custom "input" event for the test. +1. Set the new value for the input is set to *Red*, and dispatch the "input" event on the form input element. +1. Assert that the `favoriteColor` `FormControl` instance value matches the value from the input. + +The following test verifies the model to view data flow: + + + + +The steps performed in the model to view test. + +1. Use the `favoriteColor` `FormControl` instance to set the new value. +1. Query the view for the form input element. +1. Assert that the new value set on the control matches the value in the input. + +### Testing template-driven forms + +Writing tests with template-driven forms requires more detailed knowledge of the change detection process and how directives run on each cycle to ensure elements are queried, tested, or changed at the correct time. + +The following tests use the favorite color components mentioned earlier to verify the view to model and model to view data flows for a template-driven form. + +The following test verifies the view to model data flow: + + + + +The steps performed in the view to model test. + +1. Query the view for the form input element, and create a custom "input" event for the test. +1. Set the new value for the input is set to *Red*, and dispatch the "input" event on the form input element. +1. Run change detection through the test fixture. +1. Assert that the component `favoriteColor` property value matches the value from the input. + +The following test verifies the model to view data flow: + + + + +The steps performed in the model to view test. + +1. Use the component instance to set the value of `favoriteColor` property. +1. Run change detection through the test fixture. +1. Use the `tick()` method to simulate passage of time within the `fakeAsync()` task. +1. Query the view for the form input element. +1. Assert that the input value matches the `favoriteColor` value property in the component instance. + +## Mutability + +How changes are tracked plays a role in the efficiency of your application. + +- **Reactive forms** keep the data model pure by providing it as an immutable data structure. Each time a change is triggered on the data model, the `FormControl` instance returns a new data model rather than updating the data model directly. This gives you the ability track unique changes to the data model through the control's observable. This allows change detection to be more efficient because it only needs to update on unique changes. It also follows reactive patterns that integrate with observable operators to transform data. +- **Template-driven** forms rely on mutability with two-way data binding to update the data model in the component as changes are made in the template. Because there are no unique changes to track on the data model when using two-way data binding, change detection is less efficient at determining when updates are required. + +The difference is demonstrated in the examples above using the **favorite color** input element. + +- With reactive forms, the **`FormControl` instance** always returns a new value when the control's value is updated. +- With template-driven forms, the **favorite color property** is always modified to its new value. + +## Scalability + +If forms are a central part of your application, scalability is very important. Being able to reuse form models across components is critical. + +- **Reactive forms** make creating large scale forms easier by providing access to low-level APIs and synchronous access to the form model. +- **Template-driven** forms focus on simple scenarios, are not as reusable, abstract away the low-level APIs and access to the form model is provided asynchronously. The abstraction with template-driven forms surfaces in testing also, where testing reactive forms requires less setup and no dependence on the change detection cycle when updating and validating the form and data models during testing. + +## Final Thoughts + +Choosing a strategy begins with understanding the strengths and weaknesses of the options presented. Low-level API and form model access, predictability, mutability, straightforward validation and testing strategies, and scalability are all important consideration in choosing the infrastructure you use when building your forms in Angular. Template-driven forms are similar to patterns in AngularJS, but they have limitations given the criteria of many modern, large-scale Angular apps. Reactive forms integrate with reactive patterns already present in other areas of the Angular architecture, and complement those requirements well. Those limitations are alleviated with reactive forms. + +## Next Steps + +The following guides are the next steps in the learning process. + +To learn more about reactive forms, see the following guides: + +* [Reactive Forms](guide/reactive-forms) +* [Form Validation](guide/form-validation#reactive-form-validation) +* [Dynamic forms](guide/dynamic-form) + +To learn more about tempate-driven forms, see the following guides: + +* [Template-driven Forms](guide/forms) +* [Form Validation](guide/form-validation#template-driven-validation) diff --git a/aio/content/guide/reactive-forms.md b/aio/content/guide/reactive-forms.md index 32eeb5bdee50c..4a6ed6e74eb4f 100644 --- a/aio/content/guide/reactive-forms.md +++ b/aio/content/guide/reactive-forms.md @@ -16,7 +16,7 @@ Reactive forms use an explicit and immutable approach to managing the state of a Reactive forms also provide a straightforward path to testing because you are assured that your data is consistent and predictable when requested. Any consumers of the streams have access to manipulate that data safely. -Reactive forms differ from template-driven forms in distinct ways. Reactive forms provide more predictability with synchronous access to the data model, immutability with observable operators, and change tracking through observable streams. If you prefer direct access to modify data in your template, template-driven forms are less explicit because they rely on directives embedded in the template, along with mutable data to track changes asynchronously. See the [Appendix](#appendix) for detailed comparisons between the two paradigms. +Reactive forms differ from template-driven forms in distinct ways. Reactive forms provide more predictability with synchronous access to the data model, immutability with observable operators, and change tracking through observable streams. If you prefer direct access to modify data in your template, template-driven forms are less explicit because they rely on directives embedded in the template, along with mutable data to track changes asynchronously. See the [Forms Overview](guide/forms-overview) for detailed comparisons between the two paradigms. ## Getting started @@ -645,48 +645,3 @@ Listed below are the base classes and services used to create and manage form co - -### Comparison to template-driven forms - -*Template-driven* forms, introduced in the [Template-driven forms guide](guide/forms), take a completely different approach compared to reactive forms. With template-drive forms, you follow these rules: - -* Place HTML form controls (such as `` and `