首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何检测mat-stepper开始和结束的角度?

如何检测mat-stepper开始和结束的角度?
EN

Stack Overflow用户
提问于 2020-04-01 23:46:44
回答 1查看 1.7K关注 0票数 2

目前,我有一个立式垫步机。它使用*ngFor填充这些步骤。

代码语言:javascript
复制
<mat-step [stepControl]="firstFormGroup" *ngFor="let stream of selectedStreamList; let indexOfelement = index;">

所以,我想要检测这个步进器的开始和结束,作为一个变量。目前,我使用一个变量作为计数器。我递增和递减它来检测垫子的步长。但我想要一个很好的解决方案。那么有没有人可以帮我解决这个问题呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-02 02:00:28

每次步骤更改时,mat-stepper都会发出一个selectionChange事件。您可以在您的typescript文件中订阅这些更改并处理accordingly...something,可能如下所示。

代码语言:javascript
复制
//app.component.ts

import { Component, ViewChild, AfterViewInit } from "@angular/core";
import { MatStepper } from "@angular/material/stepper";
import { StepperSelectionEvent } from "@angular/cdk/stepper";
import { pluck } from "rxjs/operators";

@Component({
  selector: "app-root",
  template: `
    <mat-vertical-stepper #stepper>
      <mat-step
        *ngFor="let stream of selectedStreamList; let indexOfelement = index"
      ></mat-step>
    </mat-vertical-stepper>
  `
})
export class AppComponent implements AfterViewInit {
  @ViewChild("stepper", { static: false }) private stepper: MatStepper;

  selectedStreamList = [1, 2, 3, 4];
  isAtStart: boolean;
  isAtEnd: boolean;

  constructor() {}

  ngAfterViewInit() {
    this.stepper.selectionChange
      .pipe(pluck("selectedIndex"))
      .subscribe((res: number) => {
        this.isAtStart = res === 0;
        this.isAtEnd = res === this.selectedStreamList.length - 1;
      });
  }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60974938

复制
相关文章

相似问题

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