Could you tell me how manage the scrollToIndex (virtuall scroll) if my list is not loaded during the ngAfterViewInit lifehook? I need to call the scroll to the index when I m redirect from an other page, so in the ts file. So my goal is to point to the right index when the page is loaded
@ViewChild(CdkVirtualScrollViewport) viewport: CdkVirtualScrollViewport;
ngOnInit() {
...
this.getData(index);
}
getData(index){
return this.service.get().subscribe(data => {
this.fullDatasource = data;
this.selectedIndex = this.fullDatasource.findIndex(value => value.id === index);
}
ngAfterViewInit() {
this.viewport.scrollToIndex(this.selectedIndex);
}
Nothing happens, if I call the method in the ngAfterViewInit. Many many thnaks in advance.