I am trying to get a reference to an element which is inside dom-if using ViewChild. Actually I am using mat-stepper and want to navigate to 2nd step directly. Following is the snippets of my code;
.html
<mat-vertical-stepper #stepper *ngIf="showStepper"> component.ts
@ViewChild('stepper') stepper: MatStepper; constructor() { } ngOnInit() { this.firstFormGroup = new FormGroup({ firstCtrl: new FormControl(null, [Validators.required]) }); this.secondFormGroup = new FormGroup({ secondCtrl: new FormControl(null, [Validators.required]) }); this.stepper.selectedIndex = 1; } I want to navigate to 2nd step(1st index) directly. For this I am using ViewChild, but since mat-stepper is inside a dom-if, this.stepper is coming out to be undefined. Here is the stackblitz link to my code:
Any help would be highly appreciated.