I have this component that has a "page" basically a div, called '#results-page', that is only displayed if there are results to display.
The easiest way to describe how it works is just to show you the code:
find-page.component.ts:
import { Component } from '@angular/core';
import { NavbarComponent } from '../shared/navbar.component';
import { FindFormComponent } from '../find-page/find-form.component';
@Component({
selector: 'find-page',
templateUrl: 'app/find-page/find-page.component.html',
styleUrls: ['app/find-page/find-page.component.css' ],
directives: [ FindFormComponent ]
})
export class FindPageComponent {
showResults = false;
onResultsRecieved(recieved: boolean) {
if ( recieved ) {
this.showResults = true;
ScrollToAnchor.goToTargetBottom("#results-page");
}else {
this.showResults = false;
}
}
}
find-page.component.html:
<div id="find-page">
<find-form (onResultsRecieved)="onResultsRecieved($event)"></find-form>
</div>
<div *ngIf="showResults" id="results-page">
</div>
oResultsRecieved()
gets triggered by an event emitter when results come in. Then we set the showResults
property to true, which causes the '#results-page' to display, and as soon as it displays, I want to scroll to the bottom of that div. I'm handling the scrollToAnchor.goToTargetBottom()
just fine. However, the scrollToAnchor.goToTargetBottom()
gets triggered too early (before the '#results-page' is displayed) so it does not scroll to the bottom of the '#results-page'.
How do I cause scrollToAnchor.goToTargetBottom()
to execute, only after the '#results-page' is displayed?