ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

ion-slide-box ignores selected index

Open mobilabgit opened this issue 11 years ago • 5 comments

Hi,

For my app, I am using a nightly build from a few weeks ago. In the app I am showing soccer match results for the current selected team. For this I am using an ion-slide-box with several slides. This works great.

However, I want the slides to appear from left to right (following the date order). So the most recent match is the first you will see, and previous matches are on the left of this slide. I therefore set the selected property:

<ion-slide-box selected="data.activeSlide">

This also works great when I start up the app. However, :-) When I select another team, the slide boxes are generated again with new match results. I then set:

$scope.data.activeSlide = teamDetails.previousMatchGroups.length - 1;

Just like I do the first time when it still worked. Now, the slides start at index 0, which is not the number that I give to the activSlide property.

Following the debugger inside the ionic code I end up inside :

  // adds data to the queue for selection.
  // Index can be either a number or a getter (to be called when starting the slide)
  function select(newIndex, transitionDuration, isDrag) {
    slideQueue.unshift([
      angular.isFunction(newIndex) ? newIndex : function() { return newIndex; },
      transitionDuration || SLIDE_TRANSITION_DURATION,
      !!isDrag
    ]);
    if (!isSliding) {
      runSelectQueue();
    }
  }

Here I would suspect the selectedIndex property to be set, but this never happens. I now simply put

selectedIndex = newIndex;

to the end of this function. But admittedly, right now I am not able to oversee all the consequenses. I seems to work though...

Is this an issue for you guys to look at?

--Andre

mobilabgit avatar Dec 29 '14 17:12 mobilabgit

btw using the latest nightly build gave me lots of other problems with the slide box. So I stick to the version I am working with for the moment.

mobilabgit avatar Dec 29 '14 17:12 mobilabgit

Hey @mobilabgit, is there any chance you could put together a codepen to demonstrate this issue? It'll make it a bit easier for me to diagnose.

drewrygh avatar Dec 29 '14 18:12 drewrygh

Here you go:

http://codepen.io/anon/pen/vEXPav

mobilabgit avatar Dec 29 '14 20:12 mobilabgit

@mobilabgit You should replace setTimeout in your example with $timeout, because it triggers the digest cycle. Otherwise Angular doesn't pick up the model change. I updated your codepen.

However, for a split second you'll see the slides moving from the old index to the new one. It's not optimal.

MartinMa avatar Feb 10 '15 10:02 MartinMa

Yeah a $timeout will be needed to catch the next digest cycle. A bit cleaner solution would be to use .slide(4, 1), slide to the 4th slide in the index in 1ms.

http://codepen.io/mhartington/pen/wawwbK

mhartington avatar Apr 16 '15 20:04 mhartington