AbstractControlDirective

class

npm Package @angular/forms
Module import { AbstractControlDirective } from '@angular/forms';
Source forms/src/directives/abstract_control_directive.ts

Overview

class AbstractControlDirective {
  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
}

Description

Base class for control directives.

Only used internally in the forms module.

Subclasses

  • ControlContainer
    • AbstractFormGroupDirective
  • NgControl

Members

get control: AbstractControl | null

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

get value: any

The value of the control.

get valid: boolean | null

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

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

get invalid: boolean | null

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.

get pending: boolean | null

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.

get disabled: boolean | null

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.

get enabled: boolean | null

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

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

get errors: ValidationErrors | null

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

get pristine: boolean | null

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.

get dirty: boolean | null

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.

get touched: boolean | null

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

get status: string | null

get untouched: boolean | null

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

get statusChanges: Observable<any> | null

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

get valueChanges: Observable<any> | null

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

get path: string[] | null

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.

reset(value: any = undefined): void

Resets the form control. This means by default:

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

For more information, see AbstractControl.

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

Returns 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.

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

Returns 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.

© 2010–2018 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v5.angular.io/api/forms/AbstractControlDirective