AbstractControlDirective

Base class for control directives.

abstract class AbstractControlDirective { abstract get control: AbstractControl | null get value: any get valid: boolean | null get invalid: boolean | null get pending: boolean | null get disabled: boolean | null get enabled: boolean | null get errors: ValidationErrors | null get pristine: boolean | null get dirty: boolean | null get touched: boolean | null get status: string | null get untouched: boolean | null get statusChanges: Observable<any> | null get valueChanges: Observable<any> | null get path: string[] | null reset(value: any = undefined): void hasError(errorCode: string, path?: string[]): boolean getError(errorCode: string, path?: string[]): any }

说明

Only used internally in the forms module.

属性

属性名类型说明
control只读

The FormControl, FormGroup, or FormArray that backs this directive. Most properties fall through to that instance.

value只读

The value of the control.

valid只读

A control is valid when its status === VALID.

In order to have this status, the control must have passed all its validation checks.

invalid只读

A control is invalid when its status === INVALID.

In order to have this status, the control must have failed at least one of its validation checks.

pending只读

A control is pending when its status === PENDING.

In order to have this status, the control must be in the middle of conducting a validation check.

disabled只读

A control is disabled when its status === DISABLED.

Disabled controls are exempt from validation checks and are not included in the aggregate value of their ancestor controls.

enabled只读

A control is enabled as long as its status !== DISABLED.

In other words, it has a status of VALID, INVALID, or PENDING.

errors只读

Returns any errors generated by failing validation. If there are no errors, it will return null.

pristine只读

A control is pristine if the user has not yet changed the value in the UI.

Note that programmatic changes to a control's value will not mark it dirty.

dirty只读

A control is dirty if the user has changed the value in the UI.

Note that programmatic changes to a control's value will not mark it dirty.

touched只读

A control is marked touched once the user has triggered a blur event on it.

status只读
untouched只读

A control is untouched if the user has not yet triggered a blur event on it.

statusChanges只读

Emits an event every time the validation status of the control is re-calculated.

valueChanges只读

Emits an event every time the value of the control changes, in the UI or programmatically.

path只读

Returns an array that represents the path from the top-level form to this control. Each index is the string name of the control on that level.

方法

Resets the form control. This means by default:

reset(value: any = undefined): void

参数

value

Type: any.

可选. 默认值是 undefined.

返回值

void

  • it is marked as pristine
  • it is marked as untouched
  • value is set to null

For more information, see AbstractControl.

Returns true if the control with the given path has the error specified. Otherwise returns false.

hasError(errorCode: string, path?: string[]): boolean

参数

errorCode

Type: string.

path

Type: string[].

可选. 默认值是 undefined.

返回值

boolean

If no path is given, it checks for the error on the present control.

Returns error data if the control with the given path has the error specified. Otherwise returns null or undefined.

getError(errorCode: string, path?: string[]): any

参数

errorCode

Type: string.

path

Type: string[].

可选. 默认值是 undefined.

返回值

any

If no path is given, it checks for the error on the present control.