@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.
参见
Find out more in the Forms Overview.
入口点
主要
@angular/forms | Implements a set of directives and providers to communicate with native DOM elements when building forms to capture user input. |
主入口点的导出
模块
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. |
类
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. |
结构
AbstractControlOptions | 提供给 Interface for options provided to an |
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 |
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. |
指令
CheckboxControlValueAccessor | A |
CheckboxRequiredValidator | 该指令会借助 A Directive that adds the |
DefaultValueAccessor | The default |
EmailValidator | 该指令会借助 A directive that adds the |
FormArrayName | Syncs a nested |
FormControlDirective |
|
FormControlName | 根据名字将现有 Syncs a |
FormGroupDirective | Binds an existing |
FormGroupName | Syncs a nested |
MaxLengthValidator | 该指令用于为带有 A directive that adds max length validation to controls marked with the |
MinLengthValidator | 该指令用于为带有 A directive that adds minimum length validation to controls marked with the |
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 |
NgFormSelectorWarning | 已废弃: in Angular v6 and will be removed in Angular v9. This directive is solely used to display warnings when the deprecated |
NgModel | 根据领域对象创建一个 Creates a |
NgModelGroup | Creates and binds a |
NgSelectOption | 把选项 Marks |
PatternValidator | 该指令会借助 A directive that adds regex pattern validation to controls marked with the |
RadioControlValueAccessor | The |
RequiredValidator | 该指令会借助 A directive that adds the |
SelectControlValueAccessor | 该 The |
SelectMultipleControlValueAccessor | The |
类型
COMPOSITION_BUFFER_MODE | Provide this token to control if form directives buffer IME input until the "compositionend" event occurs. |
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. |