I have a parent component that has several components inside it:
<div class="mx-sm-auto mb-5 px-0 container">
<app-set-vehicle-details id="step1" #step1 (step1Finished)="enableStep2()"></app-set-vehicle-details>
<app-product-selection id="step2" *ngIf="step2Enabled"></app-product-selection>
<app-product-additional id="step3" *ngIf="step3Enabled"></app-product-additional>
</div>
All the child elements emmit a finished once they get unlocked and you can proceed to next step. So you enable the next step as follows:
step2Enabled = false;
enableStep2() {
this.step2Enabled = true;
this.scrollToElement('step2');
}
scrollToElement(id: string): void {
const element = document.querySelector('#' + id);
if (element) {
element.scrollIntoView({behavior: 'smooth', block: 'start', inline: 'nearest'});
}
}
So step2 component gets visible, but scroll to it it's not working.
I assume this is happening because the visibility of the second component didn't to true before the scrollToElement call, because it works once the component is visible.
How can I make this behavior to make this work?
Thanks!
display: nonecss style instead of*ngIfing those elements.