On load, I'm trying to get a ListView to scroll to the bottom. However, nothing happens. Here's what I have, running on Android:
<ListView #lv row="0" [items]="myItems" class="list-group" separatorColor="transparent" [itemTemplateSelector]="templateSelector">
Then in Typescript I have:
@ViewChild('lv') listViewElem: ElementRef;
private scrollToBottom(lv: ListView) {
if (lv && lv.items.length > 0) {
lv.scrollToIndex(lv.items.length - 1);
lv.refresh();
}
}
ngAfterViewInit() {
setTimeout(() => {
this.scrollToBottom(this.listViewElem.nativeElement);
}, 500);
}
As I debug, everything seems good. In ngAfterViewInit, listViewElem is defined, in scrollToBottomView items is set to an array with 6 elements in it. But when it's called nothing is happening.
I've also tried to just add a button to the view that when you click I call this same logic to see if it's just a load-time initialization order thing, but that doesn't work either:
<Label row="0" text="Click Me" filter(tap)="scrollNow()"></Label>
And:
public scrollNow(): void {
this.scrollToBottom(this.listViewElem.nativeElement);
}
Any ideas?