angular - 能够在 angular material2 中自定义 matstepper 中的图标

标签 angular angular-material

目前,用户只能使用 Material createdone 图标作为步骤标题。这些更改通过提供具有覆盖的 ng-template 添加了自定义图标的能力。 所以我找到了update 但是当我把它用作

<mat-horizontal-stepper [linear]="isLinear">
  <mat-step [stepControl]="firstFormGroup">
    <form [formGroup]="firstFormGroup">
      <ng-template matStepLabel>Fill out your name</ng-template>
      <ng-template matStepperIcon="edit">
        <custom-icon>edit</custom-icon>
       </ng-template>
      <mat-form-field>
        <input matInput placeholder="Last name, First name" formControlName="firstCtrl" required>
      </mat-form-field>
      <div>
        <button mat-button matStepperNext>Next</button>
      </div>
    </form>
  </mat-step>
  <mat-step>
    <ng-template matStepLabel>Done</ng-template>
    You are now done.
    <div>
      <button mat-button matStepperPrevious>Back</button>
    </div>
  </mat-step>
</mat-horizontal-stepper>

我收到这个错误

Uncaught Error: Template parse errors:
    'custom-icon' is not a known element:
    1. If 'custom-icon' is an Angular component, then verify that it is part of this module.
    2. If 'custom-icon' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

我怎样才能给我想要的图标

最佳答案

只需 install material icons

如果已安装,请在您的模块中添加导入

import {MatIconModule} from '@angular/material/icon';
@NgModule({
   imports: [
     MatIconModule
]
})

如果已经导入,请使用 <custom-icon> 代替<mat-icon>

<mat-vertical-stepper>
    <ng-template matStepperIcon="edit">
            <mat-icon>check</mat-icon>
    </ng-template>
   <!-- Stepper steps go here -->
   <mat-step label="step 1">step 1 content</mat-step>
   <mat-step label="step 2">step 2 content</mat-step>
   <mat-step label="step 3">step 3 content</mat-step>
</mat-vertical-stepper>

stackblitz example

关于angular - 能够在 angular material2 中自定义 matstepper 中的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47291778/

相关文章:

angular - window.scroll 不适用于 Angular 11 和 Material

angular - 为什么我的 Angular PWA 在 Lighthouse PWA 审核中失败,而当我手动测试它时一切正常?

css - Angular Material : How to set each mat-horizontal-stepper stepper icon with different background color in TS

angular - 在单独的组件中拆分 Angular Material 网格列表组件的 `list` 和 `item`?

angular - fxFlex 不调整元素大小

angular - 在 systemjs-builder 中解析路径

angular - 如何在 Angular 8 中正确使用 PrimeNg Toast

http - 如何避免 jsonp 请求超时错误?

angular - 使用 Angular Material 立即关闭对话框模式

javascript - 使用 Angular 指令在模板中绘制对象