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

Call $ionicSlideBoxDelegate.slide(index) in modal cause Uncaught TypeError: Cannot read property 'length' of undefined

Open Mr-Luo opened this issue 11 years ago • 10 comments

Type: BUG

Platform: mobile webview

hi,when i Call $ionicSlideBoxDelegate.slide(index) in modal it cause " Uncaught TypeError: Cannot read property 'length' of undefined" circle @ ionic.bundle.js:8178slide @ ionic.bundle.js:8207ionic.views.Slider.ionic.views.View.inherit.initialize.slide.select @ ionic.bundle.js:8560(anonymous function) @ ionic.bundle.js:105caller @ ionic.bundle.js:102$http.get.success.$ionicModal.fromTemplateUrl.then.$scope.showNumber @ app.js:271$parseFunctionCall @ ionic.bundle.js:21172$get.isolateBindingContext.(anonymous function) @ ionic.bundle.js:16519IonicModule.directive.controller.ionic.views.Slider.callback @ ionic.bundle.js:54513ionic.views.Slider.ionic.views.View.inherit.initialize.events.end @ ionic.bundle.js:8489ionic.views.Slider.ionic.views.View.inherit.initialize.events.handleEvent @ ionic.bundle.js:8326

Mr-Luo avatar Aug 21 '15 03:08 Mr-Luo

same issue here

jamescheuk91 avatar Sep 22 '15 09:09 jamescheuk91

Same error received using the $ionicModal service and setting the scope option. $ionicSlideBoxDelegate only seems to work here when the default scope is used ($rootScope). Not a solution, but a temporary one at least.

codelero avatar Sep 29 '15 12:09 codelero

Updating the condition to following in ionic.bundle.js ( function 'setup' ) worked for me.

  // do not setup if the container has no width
      if (!container.offsetWidth && !element.children.length) {
        return;
      }

srinivas-gangji avatar Oct 27 '15 19:10 srinivas-gangji

Thanks a lot @srinivas-gangji. I had the same problem and your solution worked very well for me.

YagoLopez avatar Nov 02 '15 16:11 YagoLopez

Thanks @srinivas-gangji it solve my problem too. Are we making wrong usage of $ionicSlideBoxDelegate or should it be patch ?

Keuha avatar Nov 12 '15 14:11 Keuha

This fixes the issue for me too but I don't want to be editing the bundle file. @srinivas-gangji did you want to put in a PR?

damien-m avatar Nov 23 '15 12:11 damien-m

thanks @srinivas-gangji

Mr-Luo avatar Nov 26 '15 03:11 Mr-Luo

if you are using a ionicModal and the content of the slides are rendered with ng-repeat, be sure the content is already rendered before moving to a slide with the .slide(index) function. since the modal.show() returns a promise, I use a .then(), like:

$scope.modal.show().then(function(){
      $ionicSlideBoxDelegate.slide( index );
 });

where $scope.modal is an instance of IonicModal .... i hope it was helpfull

salazarr-js avatar Dec 01 '15 18:12 salazarr-js

Hey everyone, we just landed a new slider component that solves this issue. It's in master and will be in 1.2 To use it today, do this:

Will be back porting the delegate to work with it soon, but going to close since this should be solved now.

<ion-slides options="options" slider="data.slider">
  <ion-slide-page>
  </ion-slide-page>
</ion-slides>

and your JS:

controller('MyCtrl', function($scope) {
      $scope.options = {
        loop: true
      }

      $scope.data = {};

      $scope.$watch('data.slider', function(nv, ov) {
        $scope.slider = $scope.data.slider;
      })

      $timeout(function() {
        $scope.slider.slideTo(index);
      }, 1000)

});

mlynch avatar Dec 09 '15 01:12 mlynch

The suggestion of Mr. Slzr worked perfectly. Thank you so much.

xereda avatar Dec 22 '15 14:12 xereda