Hey,
I have an ion-slides
with ngFor
inside. More or less:
<ion slides>
<ion-slide *ngFor="let item of items">
<div item-card [item]="item"></div>
</ion-slide>
<ion-slides>
items
(the list of slides) is loaded asynchronously from server in the ngAfterViewInit
:
ngAfterViewInit() {
this.fetchItemsFromServer().subscribe(
(items) => {
this.items = items
}
)
}
Everything works perfectly except one scenario:
Sometimes, I want to start from (show) a specific slide number on the page init.
I know there are slideTo
and initialSlide
methods but they don’t work for me - I think it’s because items are not yet fetched or not yet loaded into slider when I call these methods. Calling them at the end of fetchItemsFromServer().subscribe
callback seems to be to early.
Is there any way to set slider position when elements are loaded asynchronously as above?
I was also thinking about using some kind of “redraw” callback for slider but can’t find any. I am pretty sure that if I call slideTo
after items are loaded from server and *ngFor
and slider finished redraw, it’s going to work. But I don’t know how to install such a callback.
All ideas welcome! Thanks in advance.