ionic-framework: bug: Ionic2 ion-slides not properly working with *ngFor
Type: <span ionic-type>bug</span>
Ionic Version: <span ionic-version>2.x</span>
Platform: <span ionic-platform>all</span>
<span ionic-description>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.</span>
<span is-issue-template></span>
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 17
- Comments: 27 (2 by maintainers)
+1
+1
+1
+1
In my case, I delayed the creation of the slider until I have all the data needed (a simple
*ngIf="items.length"to ensure that the items array was filled with fetched data). See: https://github.com/4ian/ionic2-slides-test/blob/master/app/pages/hello-ionic/hello-ionic.htmlI made the same kinda workaround, something like what has been already posted here.
*ngIf="!isUpdatingSlides"onion-slideselement,isUpdatingSlides: boolean = false;The time outs here make sure that element has been done changing and slides already updated so we don’t get any more issues (I’ve encounter some). This will recreate the element but however on every update you will encounter a disappearance for more than 50ms and even some funny temporary behaviors but the good thing is that it works and it gives the feelings of something changed!! It’s good when you’re gonna put some dummy contents or pre-cached contents before getting actual values from server and changing it or change it with every update user might want to see.
On the swipper api you can see what you could put in the slide options. http://idangero.us/swiper/api/#.WIandPHhCkA
eg ###(onReachEnd):
mySlideOptions = { pager:true, paginationClickable: true, onReachEnd : function(){ console.log("end"); this.showButton = true; } };in the view you put the options:
<ion-slides [options]="mySlideOptions">Voila
did you manage to fix this issue? I’m facing similar issue when I try to specify an initial slide having
[hidden]active.SlideToalso doesn’t workTwo thing is really important when you are using ionic, and develop for mobile.
1, Try out your stuff without inspector window also on Chrome. 2, Instead of canvas use svg, as it’s horrible performance wise. Now my virtual scrolling started to work smoothly - there are lot’s of component which are not enough flexible, or just making me sad. (ng-lazyload-image) - it’s a very heavy stuff, ionic one is not working. simply use
… 4-5 times faster.
P.s.: ion-slide is making a mysterious 2 additional slides on the fly, which is very sensitive when the data is dynamic.
@t1gu1 It seems ionic guys are rewriting slides component.
Thank you for the workaround - helped a ton