This is the base class for FormControl, FormGroup, and FormArray.
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(validator: ValidatorFn | null, asyncValidator: AsyncValidatorFn | null)get value: anyvalidator: ValidatorFn | nullasyncValidator: AsyncValidatorFn | nullget parent: FormGroup | FormArrayThe parent control.
submitted: booleanA control is submitted if the handleSubmit function has been called on it.
get status: stringThe validation status of the control. There are four possible validation statuses:
-
VALID: control has passed all validation checks
-
INVALID: control has failed at least one validation check
-
PENDING: control is in the midst of conducting a validation check
-
DISABLED: control is exempt from validation checks
These statuses are mutually exclusive, so a control cannot be both valid AND invalid or invalid AND disabled.
get valid: booleanA control is valid when its status === VALID.
In order to have this status, the control must have passed all its validation checks.
get invalid: booleanA 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.
get pending: booleanA 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.
get disabled: booleanA 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.
get enabled: booleanA control is enabled as long as its status !== DISABLED.
In other words, it has a status of VALID, INVALID, or PENDING.
get errors: ValidationErrors | nullReturns any errors generated by failing validation. If there are no errors, it will return null.
get pristine: booleanA 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.
get dirty: booleanA 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.
get touched: booleanA control is marked touched once the user has triggered a blur event on it.
get untouched: booleanA control is untouched if the user has not yet triggered a blur event on it.
get valueChanges: Observable<any>Emits an event every time the value of the control changes, in the UI or programmatically.
get statusChanges: Observable<any>Emits an event every time the validation status of the control is re-calculated.
get updateOn: FormHooksReturns the update strategy of the AbstractControl (i.e. the event on which the control will update itself). Possible values: 'change' (default) | 'blur' | 'submit'
setValidators(newValidator: ValidatorFn | ValidatorFn[] | null): voidSets the synchronous validators that are active on this control. Calling this will overwrite any existing sync validators.
setAsyncValidators(newValidator: AsyncValidatorFn | AsyncValidatorFn[]): voidSets the async validators that are active on this control. Calling this will overwrite any existing async validators.
clearValidators(): voidEmpties out the sync validator list.
clearAsyncValidators(): voidEmpties out the async validator list.
markAsSubmitted: (opts?: {emitEvent?: boolean}) => void;Marks the control as submitted.
If the control has any children, it will also mark all children as submitted.
markAsUnsubmitted: (opts?: {emitEvent?: boolean}) => void;Marks the control as unsubmitted.
If the control has any children, it will also mark all children as unsubmitted.
markAsTouched(opts: {
onlySelf?: boolean;
emitEvent?: boolean;
} = {}): voidMarks the control as touched.
This will also mark all direct ancestors as touched to maintain the model.
markAsUntouched(opts: {
onlySelf?: boolean;
emitEvent?: boolean;
} = {}): voidMarks the control as untouched.
If the control has any children, it will also mark all children as untouched to maintain the model, and re-calculate the touched status of all parent controls.
markAsDirty(opts: {
onlySelf?: boolean;
emitEvent?: boolean;
} = {}): voidMarks the control as dirty.
This will also mark all direct ancestors as dirty to maintain the model.
markAsPristine(opts: {
onlySelf?: boolean;
emitEvent?: boolean;
} = {}): voidMarks the control as pristine.
If the control has any children, it will also mark all children as pristine to maintain the model, and re-calculate the pristine status of all parent controls.
markAsPending(opts: {
onlySelf?: boolean;
} = {}): voidMarks the control as pending.
disable(opts: {
onlySelf?: boolean;
emitEvent?: boolean;
} = {}): voidDisables the control. This means the control will be exempt from validation checks and excluded from the aggregate value of any parent. Its status is DISABLED.
If the control has children, all children will be disabled to maintain the model.
enable(opts: {
onlySelf?: boolean;
emitEvent?: boolean;
} = {}): voidEnables the control. This means the control will be included in validation checks and the aggregate value of its parent. Its status is re-calculated based on its value and its validators.
If the control has children, all children will be enabled.
setParent(parent: FormGroup | FormArray): voidsetValue(value: any, options?: Object): voidSets the value of the control. Abstract method (implemented in sub-classes).
patchValue(value: any, options?: Object): voidPatches the value of the control. Abstract method (implemented in sub-classes).
reset(value?: any, options?: Object): voidResets the control. Abstract method (implemented in sub-classes).
updateValueAndValidity(opts: {
onlySelf?: boolean;
emitEvent?: boolean;
} = {}): voidRe-calculates the value and validation status of the control.
By default, it will also update the value and validity of its ancestors.
setErrors(errors: ValidationErrors | null, opts: {
emitEvent?: boolean;
} = {}): voidSets errors on a form control.
This is used when validations are run manually by the user, rather than automatically.
Calling setErrors will also update the validity of the parent control.
###Example
const login = new FormControl("someLogin");
login.setErrors({
"notUnique": true
});get(path: Array<string | number> | string): AbstractControl | nullRetrieves a child control given the control's name or path.
Paths can be passed in as an array or a string delimited by a dot.
To get a control nested within a person sub-group:
this.form.get('person.name');-OR-
this.form.get(['person', 'name']);getError(errorCode: string, path?: string[]): anyReturns error data if the control with the given path has the error specified. Otherwise returns null or undefined.
If no path is given, it checks for the error on the present control.
hasError(errorCode: string, path?: string[]): booleanReturns true if the control with the given path has the error specified. Otherwise returns false.
If no path is given, it checks for the error on the present control.
get root: AbstractControlRetrieves the top-level ancestor of this control.
Note: This document is a derivative of "Abstract Control Document" by Google, under CC BY.