{ "id": "api/forms/AbstractControl", "title": "AbstractControl", "contents": "\n\n
\n
\n
\n \n API > @angular/forms\n
\n \n
\n \n
\n

AbstractControllink

\n \n \n \n \n \n
\n \n \n\n
\n \n
\n

This is the base class for FormControl, FormGroup, and FormArray.

\n\n

See more...

\n
\n \n \n \n
\n\nabstract class AbstractControl {\n constructor(validators: ValidatorFn | ValidatorFn[], asyncValidators: AsyncValidatorFn | AsyncValidatorFn[])\n value: any\n validator: ValidatorFn | null\n asyncValidator: AsyncValidatorFn | null\n parent: FormGroup | FormArray | null\n status: string\n valid: boolean\n invalid: boolean\n pending: boolean\n disabled: boolean\n enabled: boolean\n errors: ValidationErrors | null\n pristine: boolean\n dirty: boolean\n touched: boolean\n untouched: boolean\n valueChanges: Observable<any>\n statusChanges: Observable<any>\n updateOn: FormHooks\n root: AbstractControl\n setValidators(newValidator: ValidatorFn | ValidatorFn[]): void\n setAsyncValidators(newValidator: AsyncValidatorFn | AsyncValidatorFn[]): void\n clearValidators(): void\n clearAsyncValidators(): void\n markAsTouched(opts: { onlySelf?: boolean; } = {}): void\n markAllAsTouched(): void\n markAsUntouched(opts: { onlySelf?: boolean; } = {}): void\n markAsDirty(opts: { onlySelf?: boolean; } = {}): void\n markAsPristine(opts: { onlySelf?: boolean; } = {}): void\n markAsPending(opts: { onlySelf?: boolean; emitEvent?: boolean; } = {}): void\n disable(opts: { onlySelf?: boolean; emitEvent?: boolean; } = {}): void\n enable(opts: { onlySelf?: boolean; emitEvent?: boolean; } = {}): void\n setParent(parent: FormGroup | FormArray): void\n abstract setValue(value: any, options?: Object): void\n abstract patchValue(value: any, options?: Object): void\n abstract reset(value?: any, options?: Object): void\n updateValueAndValidity(opts: { onlySelf?: boolean; emitEvent?: boolean; } = {}): void\n setErrors(errors: ValidationErrors, opts: { emitEvent?: boolean; } = {}): void\n get(path: string | (string | number)[]): AbstractControl | null\n getError(errorCode: string, path?: string | (string | number)[]): any\n hasError(errorCode: string, path?: string | (string | number)[]): boolean\n}\n\n\n \n \n
\n

Subclasseslink

\n \n\n\n\n\n
\n \n\n
\n\n\n \n
\n

See alsolink

\n \n
\n\n\n \n \n
\n

Descriptionlink

\n

It provides some of the shared behavior that all controls and groups of controls have, like\nrunning validators, calculating status, and resetting state. It also defines the properties\nthat are shared between all sub-classes, like value, valid, and dirty. It shouldn't be\ninstantiated directly.

\n\n \n
\n\n \n\n\n\n\n\n\n

Constructorlink

\n\n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n

Initialize the AbstractControl instance.

\n\n
\n
\n \n\n constructor(validators: ValidatorFn | ValidatorFn[], asyncValidators: AsyncValidatorFn | AsyncValidatorFn[])\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n validators\n ValidatorFn | ValidatorFn[]\n

The function or array of functions that is used to determine the validity of\nthis control synchronously.

\n\n
\n \n asyncValidators\n AsyncValidatorFn | AsyncValidatorFn[]\n

The function or array of functions that is used to determine validity of\nthis control asynchronously.

\n\n
\n\n \n\n\n \n\n \n
\n
\n\n\n\n\n
\n

Propertieslink

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
PropertyDescription
\n \n value: any\n Read-Only\n \n

The current value of the control.

\n\n
    \n
  • For a FormControl, the current value.
  • \n
  • For an enabled FormGroup, the values of enabled controls as an object\nwith a key-value pair for each member of the group.
  • \n
  • For a disabled FormGroup, the values of all controls as an object\nwith a key-value pair for each member of the group.
  • \n
  • For a FormArray, the values of enabled controls as an array.
  • \n
\n\n
\n \n validator: ValidatorFn | null\n \n \n

The function that is used to determine the validity of this control synchronously.

\n\n \n
\n \n asyncValidator: AsyncValidatorFn | null\n \n \n

The function that is used to determine the validity of this control asynchronously.

\n\n \n
\n \n parent: FormGroup | FormArray | null\n Read-Only\n \n

The parent control.

\n\n \n
\n \n status: string\n Read-Only\n \n

The validation status of the control. There are four possible\nvalidation status values:

\n\n
    \n
  • VALID: This control has passed all validation checks.
  • \n
  • INVALID: This control has failed at least one validation check.
  • \n
  • PENDING: This control is in the midst of conducting a validation check.
  • \n
  • DISABLED: This control is exempt from validation checks.
  • \n
\n

These status values are mutually exclusive, so a control cannot be\nboth valid AND invalid or invalid AND disabled.

\n\n
\n \n valid: boolean\n Read-Only\n \n

A control is valid when its status is VALID.

\n\n \n

See also:

\n \n \n
\n \n invalid: boolean\n Read-Only\n \n

A control is invalid when its status is INVALID.

\n\n \n

See also:

\n \n \n
\n \n pending: boolean\n Read-Only\n \n

A control is pending when its status is PENDING.

\n\n \n

See also:

\n \n \n
\n \n disabled: boolean\n Read-Only\n \n

A control is disabled when its status is DISABLED.

\n\n

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

\n\n

See also:

\n \n \n
\n \n enabled: boolean\n Read-Only\n \n

A control is enabled as long as its status is not DISABLED.

\n\n \n

See also:

\n \n \n
\n \n errors: ValidationErrors | null\n Read-Only\n \n

An object containing any errors generated by failing validation,\nor null if there are no errors.

\n\n \n
\n \n pristine: boolean\n Read-Only\n \n

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

\n\n \n
\n \n dirty: boolean\n Read-Only\n \n

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

\n\n \n
\n \n touched: boolean\n Read-Only\n \n

True if the control is marked as touched.

\n\n

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

\n\n
\n \n untouched: boolean\n Read-Only\n \n

True if the control has not been marked as touched

\n\n

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

\n\n
\n \n valueChanges: Observable<any>\n Read-Only\n \n

A multicasting observable that emits an event every time the value of the control changes, in\nthe UI or programmatically. It also emits an event each time you call enable() or disable()\nwithout passing along {emitEvent: false} as a function argument.

\n\n \n
\n \n statusChanges: Observable<any>\n Read-Only\n \n

A multicasting observable that emits an event every time the validation status of the control\nrecalculates.

\n\n \n

See also:

\n \n \n
\n \n updateOn: FormHooks\n Read-Only\n \n

Reports the update strategy of the AbstractControl (meaning\nthe event on which the control updates itself).\nPossible values: 'change' | 'blur' | 'submit'\nDefault value: 'change'

\n\n \n
\n \n root: AbstractControl\n Read-Only\n \n

Retrieves the top-level ancestor of this control.

\n\n \n
\n
\n\n\n\n
\n

Methodslink

\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n\n \n \n
\n
\n

\n setValidators()\n \n link

\n \n
\n
\n

Sets the synchronous validators that are active on this control. Calling\nthis overwrites any existing sync validators.

\n\n
\n
\n \n\n setValidators(newValidator: ValidatorFn | ValidatorFn[]): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n newValidator\n ValidatorFn | ValidatorFn[]\n \n \n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n

When you add or remove a validator at run time, you must call\nupdateValueAndValidity() for the new validation to take effect.

\n\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n\n \n \n
\n
\n

\n setAsyncValidators()\n \n link

\n \n
\n
\n

Sets the async validators that are active on this control. Calling this\noverwrites any existing async validators.

\n\n
\n
\n \n\n setAsyncValidators(newValidator: AsyncValidatorFn | AsyncValidatorFn[]): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n newValidator\n AsyncValidatorFn | AsyncValidatorFn[]\n \n \n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n

When you add or remove a validator at run time, you must call\nupdateValueAndValidity() for the new validation to take effect.

\n\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n\n \n \n
\n
\n

\n clearValidators()\n \n link

\n \n
\n
\n

Empties out the sync validator list.

\n\n
\n
\n \n\n clearValidators(): void\n\n \n\n
Parameters
\n

There are no parameters.

\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n

When you add or remove a validator at run time, you must call\nupdateValueAndValidity() for the new validation to take effect.

\n\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n\n \n \n
\n
\n

\n clearAsyncValidators()\n \n link

\n \n
\n
\n

Empties out the async validator list.

\n\n
\n
\n \n\n clearAsyncValidators(): void\n\n \n\n
Parameters
\n

There are no parameters.

\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n

When you add or remove a validator at run time, you must call\nupdateValueAndValidity() for the new validation to take effect.

\n\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n markAsTouched()\n \n link

\n \n
\n
\n

Marks the control as touched. A control is touched by focus and\nblur events that do not change the value.

\n\n

See also:

\n
    \n \n
  • markAsUntouched()

    \n
  • \n
  • markAsDirty()

    \n
  • \n
  • markAsPristine()

    \n
  • \n
\n \n
\n
\n \n\n markAsTouched(opts: { onlySelf?: boolean; } = {}): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n opts\n object\n

Configuration options that determine how the control propagates changes\nand emits events after marking is applied.

\n
    \n
  • onlySelf: When true, mark only this control. When false or not supplied,\nmarks all direct ancestors. Default is false.\n
  • \n
\n

Optional. Default is {}.

\n\n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n markAllAsTouched()\n \n link

\n \n
\n
\n

Marks the control and all its descendant controls as touched.

\n\n

See also:

\n
    \n \n
  • markAsTouched()

    \n
  • \n
\n \n
\n
\n \n\n markAllAsTouched(): void\n\n \n\n
Parameters
\n

There are no parameters.

\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n\n \n \n
\n
\n

\n markAsUntouched()\n \n link

\n \n
\n
\n

Marks the control as untouched.

\n\n

See also:

\n
    \n \n
  • markAsTouched()

    \n
  • \n
  • markAsDirty()

    \n
  • \n
  • markAsPristine()

    \n
  • \n
\n \n
\n
\n \n\n markAsUntouched(opts: { onlySelf?: boolean; } = {}): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n opts\n object\n

Configuration options that determine how the control propagates changes\nand emits events after the marking is applied.

\n
    \n
  • onlySelf: When true, mark only this control. When false or not supplied,\nmarks all direct ancestors. Default is false.\n
  • \n
\n

Optional. Default is {}.

\n\n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n

If the control has any children, also marks all children as untouched\nand recalculates the touched status of all parent controls.

\n\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n markAsDirty()\n \n link

\n \n
\n
\n

Marks the control as dirty. A control becomes dirty when\nthe control's value is changed through the UI; compare markAsTouched.

\n\n

See also:

\n
    \n \n
  • markAsTouched()

    \n
  • \n
  • markAsUntouched()

    \n
  • \n
  • markAsPristine()

    \n
  • \n
\n \n
\n
\n \n\n markAsDirty(opts: { onlySelf?: boolean; } = {}): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n opts\n object\n

Configuration options that determine how the control propagates changes\nand emits events after marking is applied.

\n
    \n
  • onlySelf: When true, mark only this control. When false or not supplied,\nmarks all direct ancestors. Default is false.\n
  • \n
\n

Optional. Default is {}.

\n\n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n\n \n \n
\n
\n

\n markAsPristine()\n \n link

\n \n
\n
\n

Marks the control as pristine.

\n\n

See also:

\n
    \n \n
  • markAsTouched()

    \n
  • \n
  • markAsUntouched()

    \n
  • \n
  • markAsDirty()

    \n
  • \n
\n \n
\n
\n \n\n markAsPristine(opts: { onlySelf?: boolean; } = {}): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n opts\n object\n

Configuration options that determine how the control emits events after\nmarking is applied.

\n
    \n
  • onlySelf: When true, mark only this control. When false or not supplied,\nmarks all direct ancestors. Default is false.\n
  • \n
\n

Optional. Default is {}.

\n\n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n

If the control has any children, marks all children as pristine,\nand recalculates the pristine status of all parent\ncontrols.

\n\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n\n \n \n
\n
\n

\n markAsPending()\n \n link

\n \n
\n
\n

Marks the control as pending.

\n\n

See also:

\n \n \n
\n
\n \n\n markAsPending(opts: { onlySelf?: boolean; emitEvent?: boolean; } = {}): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n opts\n object\n

Configuration options that determine how the control propagates changes and\nemits events after marking is applied.

\n
    \n
  • onlySelf: When true, mark only this control. When false or not supplied,\nmarks all direct ancestors. Default is false.
  • \n
  • emitEvent: When true or not supplied (the default), the statusChanges\nobservable emits an event with the latest status the control is marked pending.\nWhen false, no events are emitted.\n
  • \n
\n

Optional. Default is {}.

\n\n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n

A control is pending while the control performs async validation.

\n\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n\n \n \n
\n
\n

\n disable()\n \n link

\n \n
\n
\n

Disables the control. This means the control is exempt from validation checks and\nexcluded from the aggregate value of any parent. Its status is DISABLED.

\n\n

See also:

\n \n \n
\n
\n \n\n disable(opts: { onlySelf?: boolean; emitEvent?: boolean; } = {}): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n opts\n object\n

Configuration options that determine how the control propagates\nchanges and emits events after the control is disabled.

\n
    \n
  • onlySelf: When true, mark only this control. When false or not supplied,\nmarks all direct ancestors. Default is false.
  • \n
  • emitEvent: When true or not supplied (the default), both the statusChanges and\nvalueChanges\nobservables emit events with the latest status and value when the control is disabled.\nWhen false, no events are emitted.\n
  • \n
\n

Optional. Default is {}.

\n\n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n

If the control has children, all children are also disabled.

\n\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n\n \n \n
\n
\n

\n enable()\n \n link

\n \n
\n
\n

Enables the control. This means the control is included in validation checks and\nthe aggregate value of its parent. Its status recalculates based on its value and\nits validators.

\n\n

See also:

\n \n \n
\n
\n \n\n enable(opts: { onlySelf?: boolean; emitEvent?: boolean; } = {}): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n opts\n object\n

Configure options that control how the control propagates changes and\nemits events when marked as untouched

\n
    \n
  • onlySelf: When true, mark only this control. When false or not supplied,\nmarks all direct ancestors. Default is false.
  • \n
  • emitEvent: When true or not supplied (the default), both the statusChanges and\nvalueChanges\nobservables emit events with the latest status and value when the control is enabled.\nWhen false, no events are emitted.\n
  • \n
\n

Optional. Default is {}.

\n\n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n

By default, if the control has children, all children are enabled.

\n\n
\n\n \n \n\n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n setParent()\n \n link

\n \n
\n
\n
\n \n\n setParent(parent: FormGroup | FormArray): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n parent\n FormGroup | FormArray\n

Sets the parent of the control

\n\n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n setValue()\n \n link

\n \n
\n
\n

Sets the value of the control. Abstract method (implemented in sub-classes).

\n\n
\n
\n \n\n abstract setValue(value: any, options?: Object): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n value\n any\n \n \n
\n \n options\n Object\n

Optional. Default is undefined.

\n \n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n patchValue()\n \n link

\n \n
\n
\n

Patches the value of the control. Abstract method (implemented in sub-classes).

\n\n
\n
\n \n\n abstract patchValue(value: any, options?: Object): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n value\n any\n \n \n
\n \n options\n Object\n

Optional. Default is undefined.

\n \n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n reset()\n \n link

\n \n
\n
\n

Resets the control. Abstract method (implemented in sub-classes).

\n\n
\n
\n \n\n abstract reset(value?: any, options?: Object): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n value\n any\n

Optional. Default is undefined.

\n \n
\n \n options\n Object\n

Optional. Default is undefined.

\n \n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n\n \n \n
\n
\n

\n updateValueAndValidity()\n \n link

\n \n
\n
\n

Recalculates the value and validation status of the control.

\n\n
\n
\n \n\n updateValueAndValidity(opts: { onlySelf?: boolean; emitEvent?: boolean; } = {}): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n opts\n object\n

Configuration options determine how the control propagates changes and emits events\nafter updates and validity checks are applied.

\n
    \n
  • onlySelf: When true, only update this control. When false or not supplied,\nupdate all direct ancestors. Default is false.
  • \n
  • emitEvent: When true or not supplied (the default), both the statusChanges and\nvalueChanges\nobservables emit events with the latest status and value when the control is updated.\nWhen false, no events are emitted.\n
  • \n
\n

Optional. Default is {}.

\n\n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n

By default, it also updates the value and validity of its ancestors.

\n\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n\n \n \n \n \n
\n
\n

\n setErrors()\n \n link

\n \n
\n
\n

Sets errors on a form control when running validations manually, rather than automatically.

\n\n
\n
\n \n\n setErrors(errors: ValidationErrors, opts: { emitEvent?: boolean; } = {}): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n errors\n ValidationErrors\n \n \n
\n \n opts\n object\n

Optional. Default is {}.

\n \n
\n\n \n
Returns
\n

void

\n\n \n\n\n \n\n \n
\n
\n

Calling setErrors also updates the validity of the parent control.

\n\n
\n

Usage Noteslink

\n
Manually set the errors for a controllink
\n\nconst login = new FormControl('someLogin');\nlogin.setErrors({\n notUnique: true\n});\n\nexpect(login.valid).toEqual(false);\nexpect(login.errors).toEqual({ notUnique: true });\n\nlogin.setValue('someOtherLogin');\n\nexpect(login.valid).toEqual(true);\n\n\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n \n \n
\n
\n

\n get()\n \n link

\n \n
\n
\n

Retrieves a child control given the control's name or path.

\n\n
\n
\n \n\n get(path: string | (string | number)[]): AbstractControl | null\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n path\n string | (string | number)[]\n

A dot-delimited string or array of string/number values that define the path to the\ncontrol.

\n\n
\n\n \n
Returns
\n

AbstractControl | null

\n\n \n\n\n \n\n \n
\n
\n

Usage Noteslink

\n
Retrieve a nested controllink
\n

For example, to get a name control nested within a person sub-group:

\n
    \n
  • this.form.get('person.name');
  • \n
\n

-OR-

\n
    \n
  • this.form.get(['person', 'name']);
  • \n
\n
Retrieve a control in a FormArraylink
\n

When accessing an element inside a FormArray, you can use an element index.\nFor example, to get a price control from the first element in an items array you can use:

\n
    \n
  • this.form.get('items.0.price');
  • \n
\n

-OR-

\n
    \n
  • this.form.get(['items', 0, 'price']);
  • \n
\n\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n \n \n
\n
\n

\n getError()\n \n link

\n \n
\n
\n

Reports error data for the control with the given path.

\n\n
\n
\n \n\n getError(errorCode: string, path?: string | (string | number)[]): any\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n errorCode\n string\n

The code of the error to check

\n\n
\n \n path\n string | (string | number)[]\n

A list of control names that designates how to move from the current control\nto the control that should be queried for errors.

\n

Optional. Default is undefined.

\n\n
\n\n \n
Returns
\n

any: error data for that particular error. If the control or error is not present,\nnull is returned.

\n\n \n\n\n \n\n \n
\n
\n

Usage Noteslink

\n

For example, for the following FormGroup:

\n\nform = new FormGroup({\n address: new FormGroup({ street: new FormControl() })\n});\n\n

The path to the 'street' control from the root form would be 'address' -> 'street'.

\n

It can be provided to this method in one of two formats:

\n
    \n
  1. An array of string control names, e.g. ['address', 'street']
  2. \n
  3. A period-delimited list of control names in one string, e.g. 'address.street'
  4. \n
\n\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n \n \n
\n
\n

\n hasError()\n \n link

\n \n
\n
\n

Reports whether the control with the given path has the error specified.

\n\n
\n
\n \n\n hasError(errorCode: string, path?: string | (string | number)[]): boolean\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n errorCode\n string\n

The code of the error to check

\n\n
\n \n path\n string | (string | number)[]\n

A list of control names that designates how to move from the current control\nto the control that should be queried for errors.

\n

Optional. Default is undefined.

\n\n
\n\n \n
Returns
\n

boolean: whether the given error is present in the control at the given path.

\n

If the control is not present, false is returned.

\n\n \n\n\n \n\n \n
\n
\n

Usage Noteslink

\n

For example, for the following FormGroup:

\n\nform = new FormGroup({\n address: new FormGroup({ street: new FormControl() })\n});\n\n

The path to the 'street' control from the root form would be 'address' -> 'street'.

\n

It can be provided to this method in one of two formats:

\n
    \n
  1. An array of string control names, e.g. ['address', 'street']
  2. \n
  3. A period-delimited list of control names in one string, e.g. 'address.street'
  4. \n
\n

If no path is given, this method checks for the error on the current control.

\n\n
\n\n \n
\n\n\n\n \n\n\n
\n
\n\n\n" }