填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

AbstractControlDirective

Base class for control directives.

查看"说明"...

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

说明

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

属性

属性说明
abstract control: AbstractControl | null只读

A reference to the underlying control.

value: any只读

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

valid: boolean | null只读

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

invalid: boolean | null只读

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

pending: boolean | null只读

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

disabled: boolean | null只读

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

enabled: boolean | null只读

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

errors: ValidationErrors | null只读

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

pristine: boolean | null只读

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

dirty: boolean | null只读

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

touched: boolean | null只读

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

status: string | null只读

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

untouched: boolean | null只读

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

statusChanges: Observable<any> | null只读

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

valueChanges: Observable<any> | null只读

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

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.

方法

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

reset(value: any = undefined): void
      
      reset(value: any = undefined): void
    
参数
value any

可选. 默认值是 undefined.

返回值

void

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

hasError(errorCode: string, path?: string | (string | number)[]): boolean
      
      hasError(errorCode: string, path?: string | (string | number)[]): boolean
    
参数
errorCode string

The code of the error to check

path string | (string | number)[]

可选. 默认值是 undefined.

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

返回值

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

If the control is not present, false is returned.

使用说明

For example, for the following FormGroup:

form = new FormGroup({ address: new FormGroup({ street: new FormControl() }) });
      
      form = new FormGroup({
  address: new FormGroup({ street: new FormControl() })
});
    

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

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

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

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

Reports error data for the control with the given path.

getError(errorCode: string, path?: string | (string | number)[]): any
      
      getError(errorCode: string, path?: string | (string | number)[]): any
    
参数
errorCode string

The code of the error to check

path string | (string | number)[]

可选. 默认值是 undefined.

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

返回值

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

使用说明

For example, for the following FormGroup:

form = new FormGroup({ address: new FormGroup({ street: new FormControl() }) });
      
      form = new FormGroup({
  address: new FormGroup({ street: new FormControl() })
});
    

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

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

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