简体   繁体   中英

How to get current ion-slide index without a next button

i have question about hybrid mobile used ionic-cordova-angular. this question about problem ionic-slide-box without button next. i try to get current index when user swift page in slidebox.

how to get current index without i create button next slide.

Did you tried this?

function MyCtrl($scope, $ionicSlideBoxDelegate) {
  $scope.getCurrentIndex = function() {
    $ionicSlideBoxDelegate.currentIndex();
  }
}

http://ionicframework.com/docs/api/service/$ionicSlideBoxDelegate/

UPDATE:

To get the box index without a button you could use the callback onSlideChange of ionSlideBox directive:

HTML:

<ion-slide-box on-slide-changed="slideHasChanged($index)">
  <ion-slide>
    <div class="box blue"><h1>BLUE</h1></div>
  </ion-slide>
  <ion-slide>
    <div class="box yellow"><h1>YELLOW</h1></div>
  </ion-slide>
  <ion-slide>
    <div class="box pink"><h1>PINK</h1></div>
  </ion-slide>
</ion-slide-box>

Inside you controller:

$scope.slideHasChanged = function($index){
  alert('slideHasChanged $index=' + $index);
  if($index === 0){
    // first box
  }
};

See this codepen demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM