【发布时间】:2020-10-25 16:57:36
【问题描述】:
我不知道如何循环遍历步进器的步骤列表,并使用 *ngFor 为每个步骤使用不同的组件。
我目前正在这样做:
<mat-horizontal-stepper
[linear]="true"
[labelPosition]="labelPosition"
(selectionChange)="onSelectionChange($event)"
[selectedIndex]="currentStep"
#stepper>
<mat-step [completed]="steps[0].completed" [label]="steps[0].label">
<app-my-component-0 [someInput0]="someInput0" (someOutput0)="onSomeOutput0($event)" *ngIf="currentStep === 0"></app-my-component-0>
</mat-step>
<mat-step [completed]="steps[1].completed" [label]="steps[1].label">
<app-my-component-1 [someInput1]="someInput1" (someOutput1)="onSomeOutput1($event)" *ngIf="currentStep === 1"></app-my-component-1>
</mat-step>
<mat-step [completed]="steps[2].completed" [label]="steps[2].label">
<app-my-component-2 [someInput2]="someInput2" (someOutput2)="onSomeOutput2($event)" *ngIf="currentStep === 2"></app-my-component-2>
</mat-step>
</mat-horizontal-stepper>
有没有更优雅的方式?我想我需要对 ngTemplate 做点什么,但我还不够熟悉,无法让它发挥作用。
【问题讨论】:
-
所以基本上你希望在每个步骤中都有不同的组件,对吗?如果是这样,为什么要使用
*ngFor? -
是的。因为我还想让
steps通用。我想要一个步骤列表,其中包括它们的组件,并且能够创建不同的步进器。 -
检查是否有帮助:netbasal.com/…