Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
getActiveIndex() returning wrong index #7616
Short description of the problem:
I setup a simple 4 images sliders, however I see several issues.
What behavior are you expecting?
I expect the getActiveIndex() to return valid indexes 0 thru array of objects length - 1
I expect the slideNext() and slidePrev() and animation if set in the option to work, however, it requires the browser to be manually resized before it starts to work.
Steps to reproduce:
Which Ionic Version? 1.x or 2.x
Plunker that shows an example of your issue
I could not get plunker to work the moment I added the code to home.ts
Updated config.js of plunker (bumped to var ngVer = '@2.0.0-rc.3';) and now the plunker is usable.
I am not familiar with config.js
In the second project I have set package.json as below
$ ionic info
Your system information:
I found an ugly workaround that is sufficient for my app:
I'm setting the index of my data array as data-id of the slide. Using the loop function, this results in several slides having the same id, which is no valid HTML, but works for my app.
This way I'm able to get the realIndex of the slide by reading it's id field:
In Ionic 2 Final the realIndex property is exposed but not documented. See https://github.com/driftyco/ionic/blob/aadf9312687963962913a8d51b3a225eedff296e/src/components/slides/slides.ts#L795
So the following is enough now:
referenced this issue
May 31, 2017
Came from #11866. jgw96 close that issue so I am posting this again here.
Thanks @jgw96 , but I believe they are different.
Their issue is having wrong activeIndex when calling slideNext().
Also tried realIndex that @PhilippStein is suggesting. But realIndex is not the "real one". Please check out the log below.
This is by far the worst component ever, spending days with this issue, sometimes after locking the swiper my slides.getActiveIndex() return true/false, how is that possible?
This issue has been automatically identified as an Ionic 3 issue. We recently moved Ionic 3 to its own repository. I am moving this issue to the repository for Ionic 3. Please track this issue over there.
If I've made a mistake, and if this issue is still relevant to Ionic 4, please let the Ionic Framework team know!
Thank you for using Ionic!