2017-10-16 39 views
1
<mat-vertical-stepper> 
<mat-step label="Agreement Preparation"> 
    <p>Agreement preparion is intiated by our side </p> 
</mat-step> 
<mat-step label="Ready for Biometric" selected active> 
    <p>Agreement preparion is intiated by our side </p> 

</mat-step> 
<mat-step label="Document in Submission"> 
    <p>Agreement preparion is intiated by our side </p> 

</mat-step> 

如何將第二步設置爲Material-2步進器中的主動步驟?

我試着設置主動和選擇,但它不工作。

回答

3

添加對步進器的引用,例如#stepper和視圖初始化後,設置stepperselectedIndex爲1

在你的模板:

<mat-vertical-stepper #stepper> 
     <mat-step label="Agreement Preparation"> 
      <p>Agreement preparion is intiated by our side </p> 
     </mat-step> 
     <mat-step label="Ready for Biometric"> 
      <p>Agreement preparion is intiated by our side </p> 
     </mat-step> 
     <mat-step label="Document in Submission"> 
      <p>Agreement preparion is intiated by our side </p> 
     </mat-step> 
    </mat-vertical-stepper> 

......在你的打字稿:

import { ViewChild, AfterViewInit } from '@angular/core'; 
import { MatStepper } from '@angular/material'; 

Component({ 
    ..... 
}) 
export class ComponentClass implements AfterViewInit { 
    @ViewChild('stepper') stepper: MatStepper; 

    ngAfterViewInit() { 
     this.stepper.selectedIndex = 1; 
    } 
} 

鏈接到StackBlitz demo

+0

你忘了'...實現AfterViewInit' :) – developer033

+0

@ developer033,這並不重要,它只需要編寫工具的目的。代碼仍然運行良好,沒有它:) – Faisal

+0

是的,我們都知道這個代碼運行良好,沒有'實現'。這只是一個偏好問題,關於遵守標準。問候:) – developer033

0

對於任何人仍在查看這個,這是我沒有實施AfterViewInit

<div *ngIf="!processing"> 
    <mat-vertical-stepper linear [selectedIndex]="currentStep"> 
     <mat-step label="Step 1">Step 1</mat-step> 
     <mat-step label="Step 2">Step 2</mat-step> 
     <mat-step label="Step 3">Step 3</mat-step> 
     <mat-step label="Step 4">Step 4</mat-step> 
    </mat-vertical-stepper> 
</div> 

我的TS文件:

ngOnInit() { 
    this.processing = true; 
    setTimeout(() => { 
     this.currentStep = 2; 
     this.processing = false; 
    }, 1500); 
} 

setTimeout()用於模擬API調用需要一些時間。這可以幫助您僅在確定知道要設置活動的索引時才顯示步進器。