填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫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.