ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
51.09k stars 13.51k forks source link

bug: ionSlideBox inside ionModal initializes incorrectly when active_slide is non-zero #4378

Closed mixersoft closed 8 years ago

mixersoft commented 9 years ago

Type: bug

Platform: all

When using ionSlideBox inside $ionicModal ionSlideBox throws an exception if the active_slide attribute is non-zero, i.e. start on slide 1 ion-slide-box[active_slide="1"]

TypeError: Cannot read property 'length' of undefined
    at circle (ionic.bundle.js:8183)
    at slide (ionic.bundle.js:8212)
    at slide.select (ionic.bundle.js:8565)
    at Object.fn (ionic.bundle.js:58470)
    at Scope.$digest (ionic.bundle.js:24515)
    at Scope.$apply (ionic.bundle.js:24783)
    at HTMLButtonElement.<anonymous> (ionic.bundle.js:57602)
    at HTMLButtonElement.eventHandler (ionic.bundle.js:12103)
    at triggerMouseEvent (ionic.bundle.js:2870)
    at tapClick (ionic.bundle.js:2859)

ionSlideBox evaluates active_slide watch variable BEFOREionic.views.Slider.setup() is complete, so slides.length is invalid. You get an Exception if active_slide is anything but 0

http://codepen.io/anon/pen/xwVRMg?editors=101

click Open Sign-in modal to trigger, and see the JS in SignInModalCtrl

vm.slideCtrl.index=1 triggers the bug. vm.slideCtrl.index=null avoids the problem by setting active_slide in a $timeout()

szuzul commented 9 years ago

+1 for that I'm having the same issue..

shaoner commented 8 years ago

same issue here, another workaround is to wait for the modal to show (i.e. having all the slides compiled):

modal.show().then(function () {
   $scope.activeSlide = 1;
});