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
}
说明
此类仅在 ReactiveFormsModule
和 FormsModule
内部使用。
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 | 只读 报告控件是否被接触过,被接触过的意思是用户已在控件上触发过 Reports whether the control is touched, meaning that the user has triggered a |
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 | 只读 报告控件是否未被接触过,未被接触过的意思是用户尚未在其上触发过 Reports whether the control is untouched, meaning that the user has not yet triggered a |
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. |
报告给定路径下的控件是否具有指定的错误。 Reports whether the control with the given path has the error specified. | ||||||
参数
返回值给定路径中的控件中是否存在给定错误。
如果控件不存在,则返回 false。 If the control is not present, false is returned. | ||||||
使用说明例如,对于以下 For example, for the following
此 '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:
如果没有给出路径,则此方法检查当前控件上的错误。 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. | ||||||
参数
返回值该特定错误的错误数据。如果控件或错误不存在,则返回 null。
| ||||||
使用说明比如下面的 For example, for the following
此 '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:
|