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

10,164

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

Share:
10,164
Arip Rahman
Author by

Arip Rahman

Updated on June 13, 2022

Comments

  • Arip Rahman
    Arip Rahman almost 2 years

    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.

  • Arip Rahman
    Arip Rahman about 9 years
    yes I've tried it. but this scope can show current index when i add button for trigger getCurrentIndex