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

AbstractControlDirectivelink

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

Base class for control directives.

\n\n

See more...

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

Subclasseslink

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

Descriptionlink

\n

This class is only used internally in the ReactiveFormsModule and the FormsModule.

\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
PropertyDescription
\n \n abstract control: AbstractControl | null\n Read-Only\n \n

A reference to the underlying control.

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

Reports the value of the control if it is present, otherwise null.

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

Reports whether the control is valid. A control is considered valid if no\nvalidation errors exist with the current value.\nIf the control is not present, null is returned.

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

Reports whether the control is invalid, meaning that an error exists in the input value.\nIf the control is not present, null is returned.

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

Reports whether a control is pending, meaning that that async validation is occurring and\nerrors are not yet available for the input value. If the control is not present, null is\nreturned.

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

Reports whether the control is disabled, meaning that the control is disabled\nin the UI and is exempt from validation checks and excluded from aggregate\nvalues of ancestor controls. If the control is not present, null is returned.

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

Reports whether the control is enabled, meaning that the control is included in ancestor\ncalculations of validity or value. If the control is not present, null is returned.

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

Reports the control's validation errors. If the control is not present, null is returned.

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

Reports whether the control is pristine, meaning that the user has not yet changed\nthe value in the UI. If the control is not present, null is returned.

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

Reports whether the control is dirty, meaning that the user has changed\nthe value in the UI. If the control is not present, null is returned.

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

Reports whether the control is touched, meaning that the user has triggered\na blur event on it. If the control is not present, null is returned.

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

Reports the validation status of the control. Possible values include:\n'VALID', 'INVALID', 'DISABLED', and 'PENDING'.\nIf the control is not present, null is returned.

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

Reports whether the control is untouched, meaning that the user has not yet triggered\na blur event on it. If the control is not present, null is returned.

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

Returns a multicasting observable that emits a validation status whenever it is\ncalculated for the control. If the control is not present, null is returned.

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

Returns a multicasting observable of value changes for the control that emits every time the\nvalue of the control changes in the UI or programmatically.\nIf the control is not present, null is returned.

\n\n \n
\n \n path: string[] | null\n Read-Only\n \n

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

\n\n \n
\n \n validator: ValidatorFn | null\n Read-Only\n \n

Synchronous validator function composed of all the synchronous validators registered with this\ndirective.

\n\n \n
\n \n asyncValidator: AsyncValidatorFn | null\n Read-Only\n \n

Asynchronous validator function composed of all the asynchronous validators registered with\nthis directive.

\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 reset()\n \n link

\n \n
\n
\n

Resets the control with the provided value if the control is present.

\n\n
\n
\n \n\n reset(value: any = undefined): void\n\n \n\n
Parameters
\n \n \n \n \n \n \n \n \n \n
\n \n value\n any\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 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 \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" }