目前,我有一个立式垫步机。它使用*ngFor填充这些步骤。
<mat-step [stepControl]="firstFormGroup" *ngFor="let stream of selectedStreamList; let indexOfelement = index;">所以,我想要检测这个步进器的开始和结束,作为一个变量。目前,我使用一个变量作为计数器。我递增和递减它来检测垫子的步长。但我想要一个很好的解决方案。那么有没有人可以帮我解决这个问题呢?
发布于 2020-04-02 02:00:28
每次步骤更改时,mat-stepper都会发出一个selectionChange事件。您可以在您的typescript文件中订阅这些更改并处理accordingly...something,可能如下所示。
//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;
});
}
}https://stackoverflow.com/questions/60974938
复制相似问题