W3cubDocs

/Angular 10

@angular/forms

package

Implements a set of directives and providers to communicate with native DOM elements when building forms to capture user input.

Use this API to register directives, build form and data models, and provide validation to your forms. Validators can be synchronous or asynchronous depending on your use case. You can also extend the built-in functionality provided by forms in Angular by using the interfaces and tokens to create custom validators and input elements.

Angular forms allow you to:

  • Capture the current value and validation status of a form.
  • Track and listen for changes to the form's data model.
  • Validate the correctness of user input.
  • Create custom validators and input elements.

You can build forms in one of two ways:

  • Reactive forms use existing instances of a FormControl or FormGroup to build a form model. This form model is synced with form input elements through directives to track and communicate changes back to the form model. Changes to the value and status of the controls are provided as observables.
  • Template-driven forms rely on directives such as NgModel and NgModelGroup create the form model for you, so any changes to the form are communicated through the template.

See also

Entry points

Primary

@angular/forms

Implements a set of directives and providers to communicate with native DOM elements when building forms to capture user input.

Primary entry point exports

NgModules

FormsModule

Exports the required providers and directives for template-driven forms, making them available for import by NgModules that import this module.

ReactiveFormsModule

Exports the required infrastructure and directives for reactive forms, making them available for import by NgModules that import this module.

Classes

AbstractControl

This is the base class for FormControl, FormGroup, and FormArray.

AbstractControlDirective

Base class for control directives.

ControlContainer

A base class for directives that contain multiple registered instances of NgControl. Only used by the forms module.

FormArray

Tracks the value and validity state of an array of FormControl, FormGroup or FormArray instances.

FormBuilder

Creates an AbstractControl from a user-specified configuration.

FormControl

Tracks the value and validation status of an individual form control.

FormGroup

Tracks the value and validity state of a group of FormControl instances.

NgControl

A base class that all FormControl-based directives extend. It binds a FormControl object to a DOM element.

Validators

Provides a set of built-in validators that can be used by form controls.

Structures

AbstractControlOptions

Interface for options provided to an AbstractControl.

AsyncValidator

An interface implemented by classes that perform asynchronous validation.

AsyncValidatorFn

A function that receives a control and returns a Promise or observable that emits validation errors if present, otherwise null.

ControlValueAccessor

Defines an interface that acts as a bridge between the Angular forms API and a native element in the DOM.

Form

An interface implemented by FormGroupDirective and NgForm directives.

Validator

An interface implemented by classes that perform synchronous validation.

ValidatorFn

A function that receives a control and synchronously returns a map of validation errors if present, otherwise null.

Directives

AbstractFormGroupDirective

A base class for code shared between the NgModelGroup and FormGroupName directives.

CheckboxControlValueAccessor

A ControlValueAccessor for writing a value and listening to changes on a checkbox input element.

CheckboxRequiredValidator

A Directive that adds the required validator to checkbox controls marked with the required attribute. The directive is provided with the NG_VALIDATORS multi-provider list.

DefaultValueAccessor
EmailValidator

A directive that adds the email validator to controls marked with the email attribute. The directive is provided with the NG_VALIDATORS multi-provider list.

FormArrayName

Syncs a nested FormArray to a DOM element.

FormControlDirective

Synchronizes a standalone FormControl instance to a form control element.

FormControlName

Syncs a FormControl in an existing FormGroup to a form control element by name.

FormGroupDirective

Binds an existing FormGroup to a DOM element.

FormGroupName

Syncs a nested FormGroup to a DOM element.

MaxLengthValidator

A directive that adds max length validation to controls marked with the maxlength attribute. The directive is provided with the NG_VALIDATORS multi-provider list.

MinLengthValidator

A directive that adds minimum length validation to controls marked with the minlength attribute. The directive is provided with the NG_VALIDATORS multi-provider list.

NgControlStatus

Directive automatically applied to Angular form controls that sets CSS classes based on control status.

NgControlStatusGroup

Directive automatically applied to Angular form groups that sets CSS classes based on control status (valid/invalid/dirty/etc).

NgForm

Creates a top-level FormGroup instance and binds it to a form to track aggregate form value and validation status.

NgModel

Creates a FormControl instance from a domain model and binds it to a form control element.

NgModelGroup

Creates and binds a FormGroup instance to a DOM element.

NgSelectOption

Marks <option> as dynamic, so Angular can be notified when options change.

NumberValueAccessor

The ControlValueAccessor for writing a number value and listening to number input changes. The value accessor is used by the FormControlDirective, FormControlName, and NgModel directives.

PatternValidator

A directive that adds regex pattern validation to controls marked with the pattern attribute. The regex must match the entire control value. The directive is provided with the NG_VALIDATORS multi-provider list.

RadioControlValueAccessor

The ControlValueAccessor for writing radio control values and listening to radio control changes. The value accessor is used by the FormControlDirective, FormControlName, and NgModel directives.

RangeValueAccessor

The ControlValueAccessor for writing a range value and listening to range input changes. The value accessor is used by the FormControlDirective, FormControlName, and NgModel directives.

RequiredValidator

A directive that adds the required validator to any controls marked with the required attribute. The directive is provided with the NG_VALIDATORS multi-provider list.

SelectControlValueAccessor

The ControlValueAccessor for writing select control values and listening to select control changes. The value accessor is used by the FormControlDirective, FormControlName, and NgModel directives.

SelectMultipleControlValueAccessor

The ControlValueAccessor for writing multi-select control values and listening to multi-select control changes. The value accessor is used by the FormControlDirective, FormControlName, and NgModel directives.

Types

COMPOSITION_BUFFER_MODE

Provide this token to control if form directives buffer IME input until the "compositionend" event occurs.

NG_ASYNC_VALIDATORS

An InjectionToken for registering additional asynchronous validators used with AbstractControls.

NG_VALIDATORS

An InjectionToken for registering additional synchronous validators used with AbstractControls.

NG_VALUE_ACCESSOR

Used to provide a ControlValueAccessor for form controls.

ValidationErrors

Defines the map of errors returned from failed validation checks.

© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v10.angular.io/api/forms