@angular/forms
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
orFormGroup
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
andNgModelGroup
create the form model for you, so any changes to the form are communicated through the template.
See also
Find out more in the Forms Overview.
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 |
AbstractControlDirective |
Base class for control directives. |
AbstractFormGroupDirective |
A base class for code shared between the |
ControlContainer |
A base class for directives that contain multiple registered instances of |
FormArray |
Tracks the value and validity state of an array of |
FormBuilder |
Creates an |
FormControl |
Tracks the value and validation status of an individual form control. |
FormGroup |
Tracks the value and validity state of a group of |
NgControl |
A base class that all control |
Validators |
Provides a set of built-in validators that can be used by form controls. |
Structures
AbstractControlOptions |
Interface for options provided to an |
AsyncValidator |
An interface implemented by classes that perform asynchronous validation. |
AsyncValidatorFn |
|
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 |
Validator |
An interface implemented by classes that perform synchronous validation. |
ValidatorFn |
Directives
CheckboxControlValueAccessor |
The accessor for writing a value and listening to changes on a checkbox input element. |
CheckboxRequiredValidator |
A Directive that adds the |
DefaultValueAccessor |
The default accessor for writing a value and listening to changes that is used by the
|
EmailValidator |
A Directive that adds the |
FormArrayName |
Syncs a nested |
FormControlDirective |
Syncs a standalone |
FormControlName |
Syncs a |
FormGroupDirective |
Binds an existing |
FormGroupName |
Syncs a nested |
MaxLengthValidator |
A directive which installs the |
MinLengthValidator |
A directive which installs the |
NgControlStatus |
Directive automatically applied to Angular form controls that sets CSS classes based on control status. The following classes are applied as the properties become true: |
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 |
NgModel |
Creates a |
NgModelGroup |
Creates and binds a |
NgSelectOption |
Marks |
PatternValidator |
A Directive that adds the |
RadioControlValueAccessor |
Writes radio control values and listens to radio control changes. |
RequiredValidator |
A Directive that adds the |
SelectControlValueAccessor |
Writes values and listens to changes on a select element. |
SelectMultipleControlValueAccessor |
The accessor for writing a value and listening to changes on a select element. |
Types
COMPOSITION_BUFFER_MODE |
Turn this mode on if you want form directives to buffer IME input until compositionend |
NG_ASYNC_VALIDATORS |
An |
NG_VALIDATORS |
An |
NG_VALUE_ACCESSOR |
Used to provide a |
ValidationErrors |
Defines the map of errors returned from failed validation checks |