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"
添加回答
舉報