AbstractControl
This is the base class for FormControl
, FormGroup
, and FormArray
.
abstract class AbstractControl {
constructor(validator: ValidatorFn | null, asyncValidator: AsyncValidatorFn | null)
value: any
validator: ValidatorFn | null
asyncValidator: AsyncValidatorFn | null
parent: FormGroup | FormArray
status: string
valid: boolean
invalid: boolean
pending: boolean
disabled: boolean
enabled: boolean
errors: ValidationErrors | null
pristine: boolean
dirty: boolean
touched: boolean
untouched: boolean
valueChanges: Observable<any>
statusChanges: Observable<any>
updateOn: FormHooks
root: AbstractControl
setValidators(newValidator: ValidatorFn | ValidatorFn[] | null): void
setAsyncValidators(newValidator: AsyncValidatorFn | AsyncValidatorFn[] | null): void
clearValidators(): void
clearAsyncValidators(): void
markAsTouched(opts: {...}): void
markAsUntouched(opts: {...}): void
markAsDirty(opts: {...}): void
markAsPristine(opts: {...}): void
markAsPending(opts: {...}): void
disable(opts: {...}): void
enable(opts: {...}): void
setParent(parent: FormGroup | FormArray): void
abstract setValue(value: any, options?: Object): void
abstract patchValue(value: any, options?: Object): void
abstract reset(value?: any, options?: Object): void
updateValueAndValidity(opts: {...}): void
setErrors(errors: ValidationErrors | null, opts: {...}): void
get(path: Array<string | number> | string): AbstractControl | null
getError(errorCode: string, path?: string[]): any
hasError(errorCode: string, path?: string[]): boolean
}
Subclasses
See also
Description
It provides some of the shared behavior that all controls and groups of controls have, like
running validators, calculating status, and resetting state. It also defines the properties
that are shared between all sub-classes, like value
, valid
, and dirty
. It shouldn't be
instantiated directly.
Constructor
Initialize the AbstractControl instance. |
||||
Parameters
|
Properties
Property | Description |
---|---|
value: any
|
Read-only.
The current value of the control.
|
validator: ValidatorFn | null
|
The function that determines the synchronous validity of this control. Declared in constructor. |
asyncValidator: AsyncValidatorFn | null
|
The function that determines the asynchronous validity of this control. Declared in constructor. |
parent: FormGroup | FormArray
|
Read-only.
The parent control. |
status: string
|
Read-only.
The validation status of the control. There are four possible validation status values:
These status values are mutually exclusive, so a control cannot be both valid AND invalid or invalid AND disabled. |
valid: boolean
|
Read-only.
A control is |
invalid: boolean
|
Read-only.
A control is |
pending: boolean
|
Read-only.
A control is |
disabled: boolean
|
Read-only.
A control is |
enabled: boolean
|
Read-only.
A control is |
errors: ValidationErrors | null
|
Read-only.
An object containing any errors generated by failing validation, or null if there are no errors. |
pristine: boolean
|
Read-only.
A control is |
dirty: boolean
|
Read-only.
A control is |
touched: boolean
|
Read-only.
True if the control is marked as A control is marked |
untouched: boolean
|
Read-only.
True if the control has not been marked as touched A control is |
valueChanges: Observable<any>
|
Read-only.
A multicasting observable that emits an event every time the value of the control changes, in the UI or programmatically. |
statusChanges: Observable<any>
|
Read-only.
A multicasting observable that emits an event every time the validation |
updateOn: FormHooks
|
Read-only.
Reports the update strategy of the |
root: AbstractControl
|
Read-only.
Retrieves the top-level ancestor of this control. |
Methods
Sets the synchronous validators that are active on this control. Calling this overwrites any existing sync validators. |
||
Parameters
Returns
|
Sets the async validators that are active on this control. Calling this overwrites any existing async validators. |
||
Parameters
Returns
|
Empties out the sync validator list. |
ParametersThere are no parameters. Returns
|
Empties out the async validator list. |
ParametersThere are no parameters. Returns
|
Marks the control as |
||
Parameters
Returns
|
||
If the control has any children, also marks all children as |
Marks the control as |
||
Parameters
Returns
|
Marks the control as |
||
Parameters
Returns
|
||
If the control has any children, marks all children as |
Marks the control as |
||
Parameters
Returns
|
||
A control is pending while the control performs async validation. |
Disables the control. This means the control is exempt from validation checks and
excluded from the aggregate value of any parent. Its status is |
||
Parameters
Returns
|
||
If the control has children, all children are also disabled. |
Enables the control. This means the control is included in validation checks and the aggregate value of its parent. Its status recalculates based on its value and its validators. |
||
Parameters
Returns
|
||
By default, if the control has children, all children are enabled. |
Parameters
Returns
|
Sets the value of the control. Abstract method (implemented in sub-classes). |
||||
Parameters
Returns
|
Patches the value of the control. Abstract method (implemented in sub-classes). |
||||
Parameters
Returns
|
Resets the control. Abstract method (implemented in sub-classes). |
||||
Parameters
Returns
|
Recalculates the value and validation status of the control. |
||
Parameters
Returns
|
||
By default, it also updates the value and validity of its ancestors. |
Sets errors on a form control when running validations manually, rather than automatically. |
||||
Parameters
Returns
|
||||
Calling |
||||
Manually set the errors for a control
|
Retrieves a child control given the control's name or path. |
||
Parameters
Returns
|
||
Retrieve a nested controlFor example, to get a
-OR-
|
Reports error data for a specific error occurring in this control or in another control. |
||||
Parameters
Returns
|
Reports whether the control with the given path has the error specified. |
||||
Parameters
Returns
|