Книга: Angular 2 Cookbook
Назад: Configuring mutual parent-child awareness with ContentChild and forwardRef
Дальше: Implementing simple two-way data binding with ngModel

Chapter 3. Building Template-Driven and Reactive Forms

This chapter will cover the following recipes:

  • Implementing simple two-way data binding with ngModel
  • Implementing basic field validation with a FormControl
  • Bundling FormControls with a FormGroup
  • Bundling FormControls with a FormArray
  • Implementing basic forms with ngForm
  • Implementing basic forms with FormBuilder and formControlName
  • Creating and using a custom validator
  • Creating and using a custom asynchronous validator with Promises

Introduction

Forms are important elemental constructs for nearly every web application, and they have been reimagined for the better in Angular 2. Angular 1 forms were very useful, but they were totally dependent on the conventions of ngModel. Angular 2's newfound conventions remove it from ngModel dependence and offer a fresh approach to form and information management that ultimately feels cleaner and more approachable.

Fundamentally, it is important to understand where and why forms are useful. There are many places in an application where multitudinous input demands association, and forms are certainly useful in this context. Angular 2 forms are best used when validating the said input, especially so when multiple-field and cross-field validation is required. Additionally, Angular forms maintain the state of various form elements, allowing the user to reason the "history" of an input field.

It is also critical to remember that the Angular 2 form behavior, much in the same way as its event and data binding, is getting integrated with the already robust browser form behavior. Browsers are already very capable of submitting data, recalling data upon a page reload, simple validation, and other behaviors that pretty much all forms rely upon. Angular 2 doesn't redefine these; rather, it integrates with these behaviors in order to link in other behaviors and data that are part of either a framework or your application.

Tip

In this chapter, be aware of the duality of the use of FormsModule and ReactiveFormsModule. They behave very differently and are almost always used separately when it comes to form construction.

Назад: Configuring mutual parent-child awareness with ContentChild and forwardRef
Дальше: Implementing simple two-way data binding with ngModel

thank you
Flame
cant read the code since it is all on a single line. Also this comments section is russian
Rakuneque
DATA COLLECTION AND ANALYSIS Two reviewers extracted data and assessed methodological quality independently lasix torsemide conversion Many others were in that space already