ion-slide-box ignores selected index
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
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.
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.
Here you go:
http://codepen.io/anon/pen/vEXPav
@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.
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