Skip to content

Commit

Permalink
feat(slides): add method to get previous index
Browse files Browse the repository at this point in the history
Slides added method wrapper: `getPreviousIndex()`

references #5508
  • Loading branch information
brandyscarney committed Apr 20, 2016
1 parent 28cb089 commit a54361c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
9 changes: 9 additions & 0 deletions ionic/components/slides/slides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,15 @@ export class Slides extends Ion {
return this.slider.activeIndex;
}

/**
* Get the index of the previous slide.
*
* @returns {number} The index number of the previous slide.
*/
getPreviousIndex(): number {
return this.slider.previousIndex;
}

/**
* Get the total number of slides.
*
Expand Down
1 change: 1 addition & 0 deletions ionic/components/slides/swiper-widget.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export declare class Swiper {
constructor(container: HTMLElement, params: any);
slides: Array<HTMLElement>;
activeIndex: number;
previousIndex: number;
isEnd: boolean;
isBeginning: boolean;
update(): any;
Expand Down
7 changes: 4 additions & 3 deletions ionic/components/slides/test/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ class MyPage {
@ViewChild('mySlider') slider: Slides;
mySlideOptions = {
initialSlide: 1,
loop: true
loop: false
};

ngAfterViewInit() {

}

onSlideChanged() {
let previousIndex = this.slider.getPreviousIndex();
let currentIndex = this.slider.getActiveIndex();
console.log("Current index is", currentIndex);
console.log("Previous index is", previousIndex, "Current index is", currentIndex);
}

goToPrevSlide() {
Expand All @@ -30,7 +31,7 @@ class MyPage {
}

goToSlide(index) {
this.slider.slideTo(index, 500, false);
this.slider.slideTo(index);
}

getIndex() {
Expand Down
7 changes: 7 additions & 0 deletions ionic/components/slides/test/controller/main.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<ion-slides #mySlider [options]="mySlideOptions" (didChange)="onSlideChanged()">
<ion-slide padding>
<h1>Slide 1</h1>
<button block (click)="goToPrevSlide()">Navigate Back</button>
<button block (click)="goToNextSlide()">Navigate Forward</button>
<button block (click)="goToSlide(2)">Navigate to 3rd Slide</button>
<button block (click)="getLength()">Get Slide Length</button>
<button block (click)="getIndex()">Get Index</button>
</ion-slide>
<ion-slide padding>
<h1>Slide 2</h1>
<button block (click)="goToPrevSlide()">Navigate Back</button>
<button block (click)="goToNextSlide()">Navigate Forward</button>
<button block (click)="goToSlide(2)">Navigate to 3rd Slide</button>
<button block (click)="getIndex()">Get Index</button>
</ion-slide>
<ion-slide padding>
<h1>Slide 3</h1>
<button block (click)="goToPrevSlide()">Navigate Back</button>
<button block (click)="goToNextSlide()">Navigate Forward</button>
<button block (click)="getIndex()">Get Index</button>
</ion-slide>
</ion-slides>

0 comments on commit a54361c

Please sign in to comment.