You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Mat-Stepper层面动态移除错误提示?

解决Mat-Stepper始终显示错误提示的问题

你当前的代码:

<mat-stepper #stepper>
  <mat-step [stepControl]="gadsForm" [attr.errorMessage]="showStepperError ? firstStepError : null">

问题出在**[attr.errorMessage]的使用方式**:

  • errorMessage是Mat-Stepper的Angular输入属性(@Input),不是原生HTML属性。用attr.前缀绑定会把它当成普通HTML属性处理,哪怕值为null,最终DOM里还是会生成errormessage="null"这个属性。而Mat-Stepper只要检测到errorMessage属性存在(不管值内容),就会触发错误提示显示。

修正方案:直接绑定到输入属性,去掉attr.前缀:

<mat-stepper #stepper>
  <mat-step [stepControl]="gadsForm" [errorMessage]="showStepperError ? firstStepError : null">

这样当showStepperError为false时,errorMessage会被设为null,Mat-Stepper会自动隐藏错误提示。

内容的提问来源于stack exchange,提问作者Elad Benda

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 18:44:57