Angular 材料 mat-form-field 中缺少关联标签 - WebStorm

Roe*_*kah 2 code-inspection webstorm angular-material angular

假设我有一个 HTML 文件:

<form mat-dialog-content [formGroup]="addressForm">
  <div class="u-flex fields-wrapper">
    <mat-form-field>
      <mat-label>Name</mat-label>
      <input type="text" matInput formControlName="name" />
    </mat-form-field>
  <button mat-raised-button (click)="submitName()">
    Submit
  </button>
</form>
Run Code Online (Sandbox Code Playgroud)

我正在开发 Angular 的 WebStorm,我总是会收到这个警告:缺少相关标签

缺少关联标签

Roe*_*kah 5

因为 Angular Material 使用mat-label代替label. WebStorm 检查将其作为警告。

作为一种解决方法,在 WebStorm 中,您可以转到Preferences | Inspections | HTML | Accessibility->Missing associated label并取消选中它。

webstorm检查设置 注意: 当您取消选中此复选框时,当您处理mat-input没有关联的label.