角材料:子组件中的MatStepper不起作用

时间:2020-08-04 14:53:34

标签: angular angular-material mat-stepper

我正在尝试在表单验证后继续处理子组件。 我可以使用matStepperNext进行下一步,但无需验证即可使用。 我尝试使用以下方法,但是stepper未定义

子组件:

@ViewChild('stepper', { static: true }) stepper: MatStepper;

...some code

if (formValid){
  this.stepper.next()
}

父组件HTML:

          <mat-horizontal-stepper #stepper [linear]="true">
            <mat-step [stepControl]="form1">
              <ng-template matStepLabel>Form 1</ng-template>
              <app-child1></app-child1>
            </mat-step>
            <mat-step [stepControl]="form2">
              <ng-template matStepLabel>Form 1</ng-template>
              <app-child2></app-child2>
            </mat-step>
            <mat-step [stepControl]="form3">
              <ng-template matStepLabel>Form 3</ng-template>
              <app-child3></app-child3>
            </mat-step>
          </mat-horizontal-stepper>

0 个答案:

没有答案