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

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

Closed Mr-Luo closed 8 years ago

Mr-Luo commented 9 years ago

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

jamescheuk91 commented 9 years ago

same issue here

codelero commented 9 years ago

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.

srinivas-gangji commented 9 years ago

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;
      }
YagoLopez commented 9 years ago

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

Keuha commented 9 years ago

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

damien-m commented 8 years ago

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?

Mr-Luo commented 8 years ago

thanks @srinivas-gangji

salazarr-js commented 8 years ago

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

mlynch commented 8 years ago

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)

});
xereda commented 8 years ago

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