'mat-label' 不是最新 Angular 材质中的已知元素错误

新手上路,请多包涵

我的 Angular 材质出现错误:

 compiler.js:466 Uncaught Error: Template parse errors:
'mat-label' is not a known element:
1. If 'mat-label' is an Angular component, then verify that it is part of this module.
2. If 'mat-label' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
        </mat-form-field>
        <mat-form-field>
            [ERROR ->]<mat-label>Both a label and a placeholder</mat-label>
            <input matInput placeholder="Simple"):

问题:

材料标签在 MatFormFieldModule 下面是链接

现在,Angular Material 不知道 Mat-Label 问题的可能原因是什么。

这是HTML

 <mat-form-field>
          <mat-label>Both a label and a placeholder</mat-label>
          <input matInput placeholder="Simple placeholder">
</mat-form-field>

原文由 Randz67 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 628
1 个回答

小心,如果你想在对话框中使用

@see https://material.angular.io/components/dialog/overview

好的

<h1 mat-dialog-title>Favorite Animal</h1>
<div mat-dialog-content>
  My favorite animal is:
  <ul>
    <li>
      <span *ngIf="data.animal === 'panda'">&#10003;</span> Panda
    </li>
    <li>
      <span *ngIf="data.animal === 'unicorn'">&#10003;</span> Unicorn
    </li>
    <li>
      <span *ngIf="data.animal === 'lion'">&#10003;</span> Lion
    </li>
  </ul>
</div>

<h1 mat-dialog-title>Favorite Animal</h1>
<div mat-dialog-content>
  <mat-label>My favorite animal is:</mat-label>
  <ul>
    <li>
      <span *ngIf="data.animal === 'panda'">&#10003;</span> Panda
    </li>
    <li>
      <span *ngIf="data.animal === 'unicorn'">&#10003;</span> Unicorn
    </li>
    <li>
      <span *ngIf="data.animal === 'lion'">&#10003;</span> Lion
    </li>
  </ul>
</div>

为此,您必须创建一个新组件,而不仅仅是一个 html 模板。

原文由 David 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进