首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Material-2步进机中将第二步设置为活动步?

如何在Material-2步进机中将第二步设置为活动步?
EN

Stack Overflow用户
提问于 2017-10-16 22:39:52
回答 3查看 24.6K关注 0票数 15
代码语言:javascript
复制
<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>

我尝试设置活动和选择,但它不起作用。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-10-16 23:00:04

添加对步进器的引用,例如#stepper,并在视图初始化后,将stepperselectedIndex设置为1。

模板中的

代码语言:javascript
复制
        <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>

...在你的打字稿中:

代码语言:javascript
复制
    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; 
        }
    }

链接到。

票数 28
EN

Stack Overflow用户

发布于 2018-01-17 13:00:09

对于还在看这篇文章的人来说,这就是我在没有实现AfterViewInit的情况下做到这一点的方法。

代码语言:javascript
复制
    <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文件:

代码语言:javascript
复制
    ngOnInit() {
        this.processing = true;
        setTimeout(() => {
          this.currentStep = 2;
          this.processing = false;
        }, 1500);
    }

setTimeout()用于模拟耗时的api调用。这有助于您仅在确定要将哪个索引设置为活动状态时才显示步进器。

票数 12
EN

Stack Overflow用户

发布于 2020-08-07 13:23:05

默认情况下,在mat-stepper selectedIndex中使用属性步进器

例如:

代码语言:javascript
复制
<mat-horizontal-stepper [linear]="isLinear" #stepper selectedIndex="2">
  <mat-label></mat-label>
</mat-horizontal-stepper>

注意:从0(零)开始索引

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46772934

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档