1 回答

TA贡献1802条经验 获得超5个赞
有一种专用方法描述了显示错误所需的条件:
private _getDefaultIndicatorLogic(step: CdkStep, isCurrentStep: boolean): StepState {
if (step._showError && step.hasError && !isCurrentStep) {
return STEP_STATE.ERROR;
}
step._showError来自STEPPER_GLOBAL_OPTIONS您在提供者中定义的
step.hasError 包括最有趣的部分
以下是所有定义:
@Input()
get hasError(): boolean {
return this._customError == null ? this._getDefaultError() : this._customError;
}
set hasError(value: boolean) {
this._customError = coerceBooleanProperty(value);
}
private _getDefaultError() {
return this.stepControl && this.stepControl.invalid && this.interacted;
}
如您所见,true如果出现hasError 返回
1)我们有stepControl无效状态和当前步骤交互
2)我们传递hasError返回true的输入道具
!isCurrentStep 意味着只有在您执行其他步骤时才会显示错误
因此,您可以hasError使用自定义逻辑将属性传递给步骤,例如:
<mat-step ... #step [hasError]="step.interacted"
添加回答
举报