填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

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

参见

入口点

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

导出模板驱动表单所需的提供者和指令,使其可用于导入了该模块的 NgModule 中。

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

ReactiveFormsModule

导出响应式表单所需的基础设施和指令,使其能用于任何导入了本模块的 NgModule 中。

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

Classes

AbstractControl

这是 FormControlFormGroupFormArray 的基类。

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

AbstractControlDirective

控件指令的基类。

Base class for control directives.

ControlContainer

包含多个已注册 NgControl 实例的指令的基类。仅由表单模块使用。

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

FormArray

跟踪一个控件数组的值和有效性状态,控件可以是 FormControlFormGroupFormArray 的实例。

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

FormBuilder

使用用户指定的配置创建 AbstractControl

Creates an AbstractControl from a user-specified configuration.

FormControl

跟踪独立表单控件的值和验证状态。

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

FormGroup

跟踪一组 FormControl 实例的值和有效性状态。

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

NgControl

FormControl 的指令扩展的基类。它将 FormControl 对象绑定到 DOM 元素。

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

提供给 AbstractControl 的配置项接口。

Interface for options provided to an AbstractControl.

AsyncValidator

由执行异步验证的类实现的接口。

An interface implemented by classes that perform asynchronous validation.

AsyncValidatorFn

本函数接收控件并返回 Promise 或 Observable,如果存在,则该函数会发出验证错误,否则为 null。

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

ControlValueAccessor

定义一个接口,该接口充当 Angular 表单 API 和 DOM 中的原生元素之间的桥梁。

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

Form

FormGroupDirectiveNgForm 实现的接口。

An interface implemented by FormGroupDirective and NgForm directives.

Validator

一个接口,实现了它的类可以扮演验证器的角色。

An interface implemented by classes that perform synchronous validation.

ValidatorFn

本函数接收控件并同步返回验证错误的映射表(如果存在),否则返回 null。

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

指令

Directives

AbstractFormGroupDirective

NgModelGroupFormGroupName 指令之间共享代码的基类。

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

CheckboxControlValueAccessor

一个 ControlValueAccessor,用于写入值并监听复选框输入元素上的更改。

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

CheckboxRequiredValidator

该指令会借助 NG_VALIDATORS 绑定把 required 验证器添加到任何带有 required 属性的检查框控件上。

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

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

EmailValidator

该指令会借助 NG_VALIDATORS 绑定把 email 验证器添加到任何带有 email 属性的控件上。

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

将嵌套的 FormArray 同步到 DOM 元素。

Syncs a nested FormArray to a DOM element.

FormControlDirective

将独立的 FormControl 实例同步到表单控件元素。

Synchronizes a standalone FormControl instance to a form control element.

FormControlName

根据名字将现有 FormGroup 中的 FormControl 与一个表单控件进行同步。

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

FormGroupDirective

将现有的 FormGroup 绑定到 DOM 元素。

Binds an existing FormGroup to a DOM element.

FormGroupName

将嵌套的 FormGroup 同步到 DOM 元素上。

Syncs a nested FormGroup to a DOM element.

MaxLengthValidator

该指令用于为带有 maxlength 属性的控件添加最大长度验证器。该指令会提供 NG_VALIDATORS 多重提供者列表。

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.

MaxValidator

A directive which installs the MaxValidatorfor any formControlName, formControl, or control with ngModel that also has a max attribute.

MinLengthValidator

该指令用于为带有 minlength 属性的控件添加最小长度验证器。该指令会提供 NG_VALIDATORS 多重提供者列表。

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.

MinValidator

A directive which installs the MinValidatorfor any formControlName, formControl, or control with ngModel that also has a min attribute.

NgControlStatus

指令自动应用于 Angular 表单控件,该控件会根据控件状态设置 CSS 类。

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

NgControlStatusGroup

该指令自动应用于 Angular 表单组,基于控件的状态(有效、无效、脏等)设置 CSS 类。

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

NgForm

创建一个顶级的 FormGroup 实例,并把它绑定到一个表单,以跟踪表单的聚合值及其验证状态。

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

NgModel

根据领域对象创建一个 FormControl 实例,并把它绑定到一个表单控件元素上。

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

NgModelGroup

创建 FormGroup 的实例并将其绑定到 DOM 元素。

Creates and binds a FormGroup instance to a DOM element.

NgSelectOption

把选项 <option> 标记为动态的,这样 Angular 就会在选项变化时得到通知。

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

NumberValueAccessor

用于写入数字值和监听数字输入框更改的 ControlValueAccessor。这个值访问器由 FormControlDirectiveFormControlNameNgModel 指令使用。

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

该指令会借助 NG_VALIDATORS 绑定来把 pattern 验证器添加到任何带有 pattern 属性的控件上。 它会使用该属性的值作为正则表达式来验证控件的值。 它会遵循 pattern 属性的语义,也就是说,该正则表达式必须匹配整个控件值。

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

ControlValueAccessor 用于写入单选控件的值和监听单选控件值的更改。这个值访问器由 FormControlDirectiveFormControlNameNgModel 指令使用。

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

ControlValueAccessor 用于写入范围输入器的值,并监听范围输入器的变化。它被 FormControlDirectiveFormControlNameNgModel 使用。

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

该指令会借助 NG_VALIDATORS 绑定把 required 验证器添加到任何带 required 属性的控件上。

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

ControlValueAccessor 用于写入 select 控件的值,并监听 select 控件的变化。该值访问器会被 FormControlDirectiveFormControlNameNgModel 指令使用。

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

ControlValueAccessor 用于写入多选控件值和监听多选控件更改。这个值访问器由 FormControlDirectiveFormControlNameNgModel 指令使用。

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

提供此令牌来控制表单指令是否要缓冲 IME 输入,直到发生“ compositionend” 事件为止。

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

NG_ASYNC_VALIDATORS

一个 InjectionToken,用于注册额外的异步验证器,供 AbstractControl 使用。

An InjectionToken for registering additional asynchronous validators used with AbstractControls.

NG_VALIDATORS

一个 InjectionToken,用于注册额外的同步验证器,供 AbstractControl 使用。

An InjectionToken for registering additional synchronous validators used with AbstractControls.

NG_VALUE_ACCESSOR

用于为表单控件提供 ControlValueAccessor

Used to provide a ControlValueAccessor for form controls.

ValidationErrors

定义从失败的验证检查返回的错误映射表。

Defines the map of errors returned from failed validation checks.