Problem with $ionicSlideBoxDelegate.currentIndex() on Android


#1

Hello

I’m having some trouble with $ionicSlideBoxDelegate.currentIndex() on Android. The weird thing is that the code works like a charm on my desktop computer(tested with Chrome, Firefox, IE). It has only been tested on a Nexus 7 running version 5.1.1.

The slider is loading content dynamically and is inspired by zarko’s post here: http://forum.ionicframework.com/t/what-should-i-do-if-i-want-to-show-thousands-of-pages-in-a-slide-box/14092/11

The index works fine as long the slide box is used normally(swiping). I have added some buttons, that makes it possible to jump between slides, much like a table of contents. When making such a jump, I basically just replace the contents of three slides, like showDefaultSlides() from zarko’s post. I have traced the whole issue back to the delegate. For some reason, some kind of decoupling is happening on Android.

Any suggestions on how to solve it?


#2

Anyone? :smile:

I tried debugging with logcat. It doesn’t produce any errors except the one that follows from the missing index.

So I tried adding a handle(“book-slider”) to the slider and used that handle when the delegate is used. It produces the following error:

I/chromium(17325): [INFO:CONSOLE(20434)] "Delegate for handle "book-slide" could
not find a corresponding element with delegate-handle="book-slide"! currentInde
x() was not called!
I/chromium(17325): Possible cause: If you are calling currentIndex() immediately
, and your element with delegate-handle="book-slide" is a child of your controll
er, then your element may not be compiled yet. Put a $timeout around your call t
o currentIndex() and try again.", source: file:///android_asset/www/lib/ionic/js
/ionic.bundle.js (20434)

The error doesn’t help at all. The DOM is fully loaded. (And works on the desktop).

Any suggestion is highly appreciated. I’m just trying in blind and not moving anywhere.


#3

I finally found a solution and I thought I would post it here, so that others can benefit from it.

A handle should be added to the slider. Instead of calling currentIndex directly, you should get the instances using _instances and fetch the first object. currentIndex() can now be called on that object and it works.

It seems like a weird workaround. Anyone knows why it has to be done this way?