When calling
this.stepper.next()
using a button on the child component, the stepper is not progressed until the second time the button is clicked.
Parent Component Html
<mat-card>
<mat-card-header>Test</mat-card-header>
<mat-card-content>
<mat-horizontal-stepper #stepper linear>
<mat-step [completed]='this.CheckIfStepCompleted(1)'>
<mat-card>
<mat-card-content>
<app-comp1 [steps]='this.steps'></app-comp1>
</mat-card-content>
<mat-card-actions align='start'>
<!-- <button mat-raised-button matStepperNext color='primary' [disabled]='!this.CheckIfStepCompleted(1)'>Next</button> -->
</mat-card-actions>
</mat-card>
</mat-step>
<mat-step [completed]='this.CheckIfStepCompleted(2)'>
<mat-card>
<mat-card-content>
<app-comp2 [steps]='this.steps'></app-comp2>
</mat-card-content>
<mat-card-actions align='start'>
<button mat-raised-button matStepperNext color='primary' [disabled]='!this.CheckIfStepCompleted(2)'>Next</button>
</mat-card-actions>
</mat-card>
</mat-step>
<mat-step [completed]='this.CheckIfStepCompleted(2)'>
<mat-card>
<mat-card-content>
<app-comp3 [steps]='this.steps'></app-comp3>
</mat-card-content>
<mat-card-actions align='start'>
<button mat-raised-button matStepperPrevious color='primary' [disabled]='!this.CheckIfStepCompleted(2)'>Back</button>
</mat-card-actions>
</mat-card>
</mat-step>
</mat-horizontal-stepper>
</mat-card-content>
</mat-card>
Child Component Html
<button (click)='this.Complete()' mat-raised-button color='accent'>Complete</button>
Child Component ts file
import { Component, Input, NgZone, OnInit, ViewChild, ViewChildren } from '@angular/core';
import { MatHorizontalStepper } from '@angular/material/stepper';
import { Step, SteppperService } from '../../services/stepper/steppper.service';
@Component({
selector: 'app-comp1',
templateUrl: './comp1.component.html',
styleUrls: ['./comp1.component.css']
})
export class Comp1Component implements OnInit {
@Input() steps: Step[] = [];
constructor(private _stepSvc: SteppperService, private readonly stepper: MatHorizontalStepper, private ngZone: NgZone) { }
selectedIndex: number = this.stepper.selectedIndex;
ngOnInit(): void {
}
Complete() {
this._stepSvc.CompleteStep(this.steps, 1).then(() => this.stepper.next());
// this.ProgressStep();
}
ProgressStep() {
this.ngZone.run(() => {
this.stepper.next();
});
}
}
We have also tried creating a function on the parent and having a event be emitted from the child component to trigger the next().
TLDR: I need to trigger the next() for the stepper located on the parent component, but I need to trigger it from the child component.