Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

bug: Ionic2 ion-slides not properly working with *ngFor #89

Open
ionitron-bot bot opened this issue Nov 1, 2018 · 3 comments
Open

bug: Ionic2 ion-slides not properly working with *ngFor #89

ionitron-bot bot opened this issue Nov 1, 2018 · 3 comments
Labels

Comments

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 1, 2018

Type: bug

Ionic Version: 2.x

Platform: all

Hey Ionic 2 team,

Ionic 2 ion-slides component seems to be working properly when ion-slide are either hardcoded into the template or when they are created with a ngFor iterating over an array that is not empty/not modified.
If the ngFor is first iterating over an empty array and then the array is modified, the slides seems to be broken (in particular, looping is not working properly).

This bug can maybe be generalised to any ion-slides that are dynamically added/removed after the first creation of the ion-slides but I have not tested this.

To reproduce the bug, clone, install and launch the sample app of this repo: https://github.com/4ian/ionic2-slides-test

Click on the button to fill the array used to generate the slides. The second slider won't work properly. The first slider will be working but I've used a workaround: the slider is not created when the array is empty.

@greaterking
Copy link

greaterking commented Apr 23, 2019

Confirming this is still an issue in ionic4.
@kinglionsoft ionic-team/ionic-framework#6515 (comment) suggested
using a 500 millisecond timeout to call update() this actually worked for me.

    setTimeout(()=>{
      this.slider.update(); //slider ..the ion-slides instance
    }, 500);

Even 100 millisecond worked for me as well (it may depend on how large the number of slides you have is.

@sjokoladepudding
Copy link

i use this

html:
(ionSlideDrag)="ionSlideDrag()"

ts:
ionSlideDrag() { if (this.slider.length() > 0) { if ((this.slider.getActiveIndex() + 1) == this.slider.length()) { this.slider.lockSwipeToNext(true); } else { this.slider.lockSwipeToNext(false); } } }

@dexterrustia
Copy link

Di anyone already find the solution for this? i already tried everything suggest in the previous post(ionic-team/ionic-framework#6515) like delaying the loading of the slides to wait for the data to come in but this doesn't work for me.. i also try *ngIf on the parent element but same thing. any advice is much appreciated. THANKS

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants