填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫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
  validator: ValidatorFn | null
  asyncValidator: AsyncValidatorFn | null
  reset(value: any = undefined): void
  hasError(errorCode: string, path?: string | (string | number)[]): boolean
  getError(errorCode: string, path?: string | (string | number)[]): any
}
    

說明

此類別僅在 ReactiveFormsModuleFormsModule 內部使用。

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

屬性

屬性說明
abstract control: AbstractControl | null唯讀

對基礎控制元件的參考。

A reference to the underlying control.

value: any唯讀

報告控制元件的值(如果存在),否則為 null。

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

valid: boolean | null唯讀

報告控制元件是否有效。如果當前值不存在驗證錯誤,則控制元件被視為有效。如果控制元件不存在,則返回 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唯讀

報告控制元件是否無效,表示輸入值中存在錯誤。如果控制元件不存在,則返回 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唯讀

報告控制元件是否處於掛起狀態,這意味著非同步驗證正在發生,並且錯誤尚未可用於輸入值。如果控制元件不存在,則返回 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唯讀

報告該控制元件是否被禁用,這意味著該控制元件在 UI 中被禁用,並且免於進行驗證檢查,並被排除在祖先控制元件的聚合值之外。如果控制元件不存在,則返回 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唯讀

報告控制元件是否被啟用,這意味著控制元件已包含在祖先的有效性計算或值計算中。如果控制元件不存在,則返回 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唯讀

報告控制元件的驗證錯誤。如果控制元件不存在,則返回 null。

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

pristine: boolean | null唯讀

報告控制元件是否為原始狀態,原始的意思是使用者尚未更改過 UI 中的值。如果控制元件不存在,則返回 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唯讀

報告控制元件是否髒狀態,髒的意思是使用者已更改過 UI 中的值。如果控制元件不存在,則返回 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唯讀

報告控制元件是否被接觸過,被接觸過的意思是使用者已在控制元件上觸發過 blur 事件。如果控制元件不存在,則返回 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唯讀

報告控制元件的驗證狀態。可能的值包括:“VALID”、“INVALID”、“DISABLED” 和 “PENDING”。如果控制元件不存在,則返回 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唯讀

報告控制元件是否未被接觸過,未被接觸過的意思是使用者尚未在其上觸發過 blur 事件。如果控制元件不存在,則返回 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唯讀

返回一個多播的可觀察物件,它會發出為此控制元件計算過的驗證狀態。如果控制元件不存在,則返回 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唯讀

返回控制元件值變更的多播可觀察物件,它會在每次控制元件的值在 UI 中或以程式設計方式更改時觸發。如果控制元件不存在,則返回 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.

validator: ValidatorFn | null唯讀

同步驗證器函式,由使用此指令註冊的所有同步驗證器組合而成。

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

asyncValidator: AsyncValidatorFn | null唯讀

非同步驗證器函式,由使用此指令註冊的所有非同步驗證器組合而成。

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

方法

如果此控制元件存在,則使用所提供的值重置它。

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

      
      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
    
引數
errorCode string

要檢查的錯誤程式碼

The code of the error to check

path string | (string | number)[]

控制元件名稱列表,用於指定如何從當前控制元件移至要查詢錯誤的控制元件。

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

可選. 預設值是 `undefined`.
返回值

給定路徑中的控制元件中是否存在給定錯誤。

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

如果控制元件不存在,則返回 false。

If the control is not present, false is returned.

使用說明

例如,對於以下 FormGroup

For example, for the following FormGroup:

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

此 'street' 控制元件的從根表單開始的路徑應該是 'address' -> 'street'。

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. 控制元件名稱的字串陣列,如 ['address', 'street']

    An array of string control names, e.g. ['address', 'street']

  2. 以一個字串表示的句號分隔的控制元件名稱列表,如 'address.street'

    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
    
引數
errorCode string

要檢查的錯誤程式碼

The code of the error to check

path string | (string | number)[]

控制元件名稱列表,用於指定如何從當前控制元件移至要查詢錯誤的控制元件。

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

可選. 預設值是 `undefined`.
返回值

該特定錯誤的錯誤資料。如果控制元件或錯誤不存在,則返回 null。

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

使用說明

比如下面的 FormGroup

For example, for the following FormGroup:

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

此 'street' 控制元件的從根表單開始的路徑應該是 'address' -> 'street'。

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. 控制元件名稱的字串陣列,如 ['address', 'street']

    An array of string control names, e.g. ['address', 'street']

  2. 以一個字串表示的句號分隔的控制元件名稱列表,如 'address.street'

    A period-delimited list of control names in one string, e.g. 'address.street'