Angular 9 - 删除 Angular Material 步进器上的默认图标(创建)
Angular 9 - Remove default icon (create) on Angular Material Stepper
我在使用 Angular 时遇到了这个恼人的问题:我通过添加到页面的 provides
覆盖了步进器图标:
provide: STEPPER_GLOBAL_OPTIONS, useValue: {displayDefaultIndicatorType: false, showError: true}
这是HTML页(只是一个,有7个元素copy/pasted):
<mat-horizontal-stepper>
<!-- AREA -->
<mat-step label="Step 1" state="area">
<p>Put down your phones</p>
<div>
<button mat-button matStepperNext>Next</button>
</div>
</mat-step>
<!-- QUESTION -->
<mat-step label="Step 2" state="question">
<p>Socialize with each other</p>
<div>
<button mat-button matStepperPrevious>Back</button>
<button mat-button matStepperNext>Next</button>
</div>
</mat-step>
<!-- MODE -->
<mat-step label="Step 3" state="mode">
<p>Socialize with each other</p>
<div>
<button mat-button matStepperPrevious>Back</button>
<button mat-button matStepperNext>Next</button>
</div>
</mat-step>
...
<!-- Icon overrides -->
<!-- AREA -->
<ng-template matStepperIcon="area">
<mat-icon>gavel</mat-icon>
</ng-template>
<!-- QUESTION -->
<ng-template matStepperIcon="question">
<mat-icon>contact_support</mat-icon>
</ng-template>
<!-- MODE -->
<ng-template matStepperIcon="mode">
<mat-icon>forum</mat-icon>
</ng-template>
...
如您所见,这只是您可以在 Angular 9 documentation
上找到的示例
好了,现在用几张图来介绍问题:
看看圈子,里面应该有自己的图标(木槌,constact_support,论坛)。但是当我执行这些步骤之一时,它会将图标替换为另一个图标,准确地说是 create icon.
现在,如果我回到第二步,进入圆圈生成正确的图标,没有这种烦人的覆盖:
我已经试过了:
- 在
<mat-step>
组件上设置 [completed]=false
,但它只是删除了前面圆圈中的复选图标
- 覆盖图标:
<ng-template matStepperIcon="edit">
<mat-icon>gavel</mat-icon>
</ng-template>
但是没有用,因为它只是覆盖了图标,所以问题仍然存在。我还尝试将 <mat-icon></mat-icon>
留空,但当然它只会在圆圈中留下一个空白图标。
我想要实现的是绕过这个 "automatic overwriting"。有什么想法吗?
here 是适合我的解决方案
<mat-horizontal-stepper #stepper>
<mat-step label="Information">...</mat-step>
<mat-step label="Groups">...</mat-step>
<mat-step label="Validate">...</mat-step>
<ng-template matStepperIcon="number" let-index="index">
<mat-icon>{{index === 0 ? 'perm_contact_calendar' : index === 1 ? 'group' : 'done'}}</mat-icon>
</ng-template>
</mat-horizontal-stepper>
@Component({
selector: 'app-stepper-component',
templateUrl: './stepper.component.html',
styleUrls: ['./stepper.component.scss']
})
export class StepperComponent implements AfterViewInit {
@ViewChild('stepper') stepper: MatHorizontalStepper;
ngAfterViewInit() {
this.stepper._getIndicatorType = () => STEP_STATE.NUMBER;
}
}
或者,覆盖 matStepperIcon="number"
和 matStepperIcon="edit"
:
<mat-horizontal-stepper>
<mat-step label="Information">...</mat-step>
<mat-step label="Groups">...</mat-step>
<mat-step label="Validate">...</mat-step>
<ng-template matStepperIcon="number" let-index="index">
<mat-icon>{{index === 0 ? 'perm_contact_calendar' : index === 1 ? 'group' : 'done'}}</mat-icon>
</ng-template>
<ng-template matStepperIcon="edit" let-index="index">
<mat-icon>{{index === 0 ? 'perm_contact_calendar' : index === 1 ? 'group' : 'done'}}</mat-icon>
</ng-template>
</mat-horizontal-stepper>
我在使用 Angular 时遇到了这个恼人的问题:我通过添加到页面的 provides
覆盖了步进器图标:
provide: STEPPER_GLOBAL_OPTIONS, useValue: {displayDefaultIndicatorType: false, showError: true}
这是HTML页(只是一个,有7个元素copy/pasted):
<mat-horizontal-stepper>
<!-- AREA -->
<mat-step label="Step 1" state="area">
<p>Put down your phones</p>
<div>
<button mat-button matStepperNext>Next</button>
</div>
</mat-step>
<!-- QUESTION -->
<mat-step label="Step 2" state="question">
<p>Socialize with each other</p>
<div>
<button mat-button matStepperPrevious>Back</button>
<button mat-button matStepperNext>Next</button>
</div>
</mat-step>
<!-- MODE -->
<mat-step label="Step 3" state="mode">
<p>Socialize with each other</p>
<div>
<button mat-button matStepperPrevious>Back</button>
<button mat-button matStepperNext>Next</button>
</div>
</mat-step>
...
<!-- Icon overrides -->
<!-- AREA -->
<ng-template matStepperIcon="area">
<mat-icon>gavel</mat-icon>
</ng-template>
<!-- QUESTION -->
<ng-template matStepperIcon="question">
<mat-icon>contact_support</mat-icon>
</ng-template>
<!-- MODE -->
<ng-template matStepperIcon="mode">
<mat-icon>forum</mat-icon>
</ng-template>
...
如您所见,这只是您可以在 Angular 9 documentation
上找到的示例好了,现在用几张图来介绍问题:
看看圈子,里面应该有自己的图标(木槌,constact_support,论坛)。但是当我执行这些步骤之一时,它会将图标替换为另一个图标,准确地说是 create icon.
现在,如果我回到第二步,进入圆圈生成正确的图标,没有这种烦人的覆盖:
我已经试过了:
- 在
<mat-step>
组件上设置[completed]=false
,但它只是删除了前面圆圈中的复选图标 - 覆盖图标:
<ng-template matStepperIcon="edit">
<mat-icon>gavel</mat-icon>
</ng-template>
但是没有用,因为它只是覆盖了图标,所以问题仍然存在。我还尝试将 <mat-icon></mat-icon>
留空,但当然它只会在圆圈中留下一个空白图标。
我想要实现的是绕过这个 "automatic overwriting"。有什么想法吗?
here 是适合我的解决方案
<mat-horizontal-stepper #stepper>
<mat-step label="Information">...</mat-step>
<mat-step label="Groups">...</mat-step>
<mat-step label="Validate">...</mat-step>
<ng-template matStepperIcon="number" let-index="index">
<mat-icon>{{index === 0 ? 'perm_contact_calendar' : index === 1 ? 'group' : 'done'}}</mat-icon>
</ng-template>
</mat-horizontal-stepper>
@Component({
selector: 'app-stepper-component',
templateUrl: './stepper.component.html',
styleUrls: ['./stepper.component.scss']
})
export class StepperComponent implements AfterViewInit {
@ViewChild('stepper') stepper: MatHorizontalStepper;
ngAfterViewInit() {
this.stepper._getIndicatorType = () => STEP_STATE.NUMBER;
}
}
或者,覆盖 matStepperIcon="number"
和 matStepperIcon="edit"
:
<mat-horizontal-stepper>
<mat-step label="Information">...</mat-step>
<mat-step label="Groups">...</mat-step>
<mat-step label="Validate">...</mat-step>
<ng-template matStepperIcon="number" let-index="index">
<mat-icon>{{index === 0 ? 'perm_contact_calendar' : index === 1 ? 'group' : 'done'}}</mat-icon>
</ng-template>
<ng-template matStepperIcon="edit" let-index="index">
<mat-icon>{{index === 0 ? 'perm_contact_calendar' : index === 1 ? 'group' : 'done'}}</mat-icon>
</ng-template>
</mat-horizontal-stepper>