在弹出窗口打开之前,步进器会进入下一步,这是很正常的,因为您是在stepChage事件中打开弹出窗口的,当您单击带有matStepperNext指令的按钮时,会调用stepChage。
您可以通过在下一个按钮中使用自定义点击事件而不是matStepperNext指令来使其工作,如下所示:
<mat-horizontal-stepper [linear]="false" #stepper>
<mat-step [stepControl]="firstFormGroup">
<form [formGroup]="firstFormGroup">
<ng-template matStepLabel>Fill out your name</ng-template>
<mat-form-field>
<input matInput placeholder="Last name, First name" formControlName="firstCtrl" required>
</mat-form-field>
<div>
<button mat-button (click)="goToNextStep()">Next</button>
</div>
</form>
</mat-step>
<mat-step [stepControl]="secondFormGroup">
<form [formGroup]="secondFormGroup">
<ng-template matStepLabel>Fill out your address</ng-template>
<mat-form-field>
<input matInput placeholder="Address" formControlName="secondCtrl" required>
</mat-form-field>
<div>
<button mat-button matStepperPrevious>Back</button>
<button mat-button (click)="goToNextStep()">Next</button>
</div>
</form>
</mat-step>
<mat-step>
<ng-template matStepLabel>Done</ng-template>
You are now done.
<div>
<button mat-button matStepperPrevious>Back</button>
<button mat-button (click)="stepper.reset()">Reset</button>
</div>
</mat-step>
</mat-horizontal-stepper>
您的goToNextStep方法将包含:
goToNextStep(): void {
const dialogRef = this.dialog.open(DialogMessageN2Component, {
width: '500px',
height: '500px',
data: {},
});
dialogRef.afterClosed().subscribe((result) => {
console.log('The dialog was closed' + JSON.stringify(result));
if (result.data === 'yes') {
console.log('yes');
this.stepper.next();
}
});
}
别忘了添加
@ViewChild('stepper') stepper: MatHorizontalStepper;
在您的组件中。