如何使用角形材质步进器和角形6使上一步的selectedIndex步骤的所有步骤处于活动状态

时间:2019-07-06 15:54:30

标签: angular angular-material angular6 angular-material-6

我已经使用了角形材料步进器,我需要激活所有先前的步骤,直到在角度6中的selectedIndex步骤为止。我已经尝试过使用线性步进器,但是我对selectedIndex仅获得了有效步进,而对所有先前的索引都没有。步骤,然后选择第3个步骤,在剩余的第1个和第2个步骤无效的情况下,我只有第3个步骤,我需要激活第1、2、3个步骤

角6,角材料6

in html

<div class="col-lg-7" *ngIf="!process">
                           <mat-horizontal-stepper [linear]="isLinear" 
 [selectedIndex]="currentStep" #stepper>
                             <ng-container *ngFor="let step of steps">
                                   <ng-template matStepperIcon="home">
                                       <mat-icon>home</mat-icon>
                                     </ng-template>
                               <mat-step  [editable]="isEditable">
                                 <ng-template matStepLabel>{{step}}</ng- 
    template>
                               </mat-step>
                             </ng-container>
                           </mat-horizontal-stepper>
                         </div>  

in ts

```
isLinear = true;
      process: Boolean;
      steps = [ "Ordered", "Packed", "Shipped", 'Transit', "Delivered" ];
      this.process = true;
        setTimeout(() => {
          this.currentStep = 2;
          this.process = false;
        }, 1500);

I expected first three steps are active mode but i got only 3rd step in active mode

1 个答案:

答案 0 :(得分:0)

您可以将所选步骤之前的步骤标记为已完成:

<mat-horizontal-stepper [linear]="isLinear" [selectedIndex]="currentStep" #stepper>
    <ng-container *ngFor="let step of steps; index as i">
        <ng-template matStepperIcon="home">
            <mat-icon>home</mat-icon>
        </ng-template>
        <mat-step #matStep [editable]="isEditable" 
                [completed]="matStep.interacted || i < currentStep">
            <ng-template matStepLabel>{{step}}</ng-template>
        </mat-step>
    </ng-container>
</mat-horizontal-stepper>