Skip to content

Commit

Permalink
docs(slides): update API docs for slides with usage information
Browse files Browse the repository at this point in the history
also updated the test for controller.

references #5508 closes ionic-team/ionic-site#458
  • Loading branch information
brandyscarney committed Apr 19, 2016
1 parent 010fb2a commit ee4869a
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 35 deletions.
96 changes: 83 additions & 13 deletions ionic/components/slides/slides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import {Scroll} from '../scroll/scroll';
* After creating and configuring the slides, you can navigate between them
* by swiping or calling methods on the `Slides` instance. You can call `slideTo()` to
* navigate to a specific slide, or `slideNext()` to change to the slide that follows
* the active slide. All of the [methods](#instance-methods) provided by the `Slides`
* the active slide. All of the [methods](#instance-members) provided by the `Slides`
* instance are listed below. See [Usage](#usage) below for more information on
* navigating between slides.
*
Expand All @@ -66,38 +66,108 @@ import {Scroll} from '../scroll/scroll';
*
*
* @usage
*
* You can add slides to a `@Page` using the following template:
*
* ```html
* <ion-slides>
* <ion-slide>
* <p>Slide 1</p>
* <button (click)="goToSlide(3)">Navigate</button>
* <h1>Slide 1</h1>
* </ion-slide>
* <ion-slide>
* <p>Slide 2</p>
* <h1>Slide 2</h1>
* </ion-slide>
* <ion-slide>
* <p>Slide 3</p>
* <h1>Slide 3</h1>
* </ion-slide>
* </ion-slides>
* ```
*
* To add [options](#configuring), we will define them in `mySlideOptions` in our class `MyPage`:
*
* ```ts
* import {Page, Slides} from 'ionic-angular';
*
* @Page({
* templateUrl: 'my-page.html'
* })
* class MyPage {
* mySlideOptions = {
* initialSlide: 1,
* loop: true
* };
* }
* ```
*
* This is setting the second slide as the initial slide on load, since
* the `initialSlide` begins at `0`. We are also setting `loop` to true which
* allows us to swipe from the last slide to the first continuously. Then,
* we will pass `mySlideOptions` in the `options` property of the `<ion-slides>`
* element. We are using [property binding](https://angular.io/docs/ts/latest/guide/template-syntax.html#!#property-binding)
* on `options` because `mySlideOptions` is an expression:
*
* ```html
* <ion-slides [options]="mySlideOptions">
* ```
*
* To grab a reference to the Slides, we will add a [local template variable](https://angular.io/docs/ts/latest/guide/template-syntax.html#!#local-vars)
* to `<ion-slides>` called `mySlider`:
*
* ```html
* <ion-slides #mySlider [options]="mySlideOptions">
* ```
*
* Next, we can use `ViewChild` to assign the Slides instance to `slider`:
*
* ```ts
* import {ViewChild} from 'angular2/core';
* import {App, Slides} from 'ionic-angular';
*
* class MyPage {
* @ViewChild('mySlider') slider: Slides;
*
* @App({
* templateUrl: 'main.html'
* })
* class MyApp {
* @ViewChild(Slides) slider: Slides;
* ...
* }
* ```
*
* Now we can call any of the `Slider` [methods]((#instance-members)),
* for example we can use the Slider's `slideTo()` method in order to
* navigate to a specific slide on a button click. Below we call the
* `goToSlide()` method and it navigates to the 3rd slide:
*
* ```ts
* class MyPage {
* ...
*
* goToSlide() {
* this.slider.slideTo(2, 500);
* }
* }
* ```
*
* We can also add events to listen to on the `<ion-slides>` element.
* Let's add the `didChange` event and call a method when the slide changes:
*
* ```html
* <ion-slides #mySlider (didChange)="onSlideChanged()" [options]="mySlideOptions">
* ```
*
* goToSlide(index) {
* this.slider.slideTo(index, 500);
* In our class, we add the `onSlideChanged()` method which gets the active
* index and prints it:
*
* ```ts
* class MyPage {
* ...
*
* onSlideChanged() {
* let currentIndex = this.slider.getActiveIndex();
* console.log("Current index is", currentIndex);
* }
* }
* ```
*
* For all of the methods you can call on the `Slider` instance, see the
* [Instance Members](#instance-members).
*
* @demo /docs/v2/demos/slides/
* @see {@link /docs/v2/components#slides Slides Component Docs}
*
Expand Down
34 changes: 17 additions & 17 deletions ionic/components/slides/test/controller/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,35 @@
import {ViewChild} from 'angular2/core';
import {App, Slides} from 'ionic-angular';
import {App, Page, Slides} from 'ionic-angular';


@App({
templateUrl: 'main.html'
})
class MyApp {
mySlideOptions: any;
@ViewChild(Slides) slider: Slides;

constructor() {
console.log("here");
this.mySlideOptions = {
initialSlide: 1,
autoplay: 1000
};
}
class MyPage {
@ViewChild('mySlider') slider: Slides;
mySlideOptions = {
initialSlide: 1,
loop: true
};

ngAfterViewInit() {

}

onSlideChanged() {
console.log("Slide Changed");
let isEnd = this.slider.isEnd();
console.log("This is the last slide?", isEnd);
let currentIndex = this.slider.getActiveIndex();
console.log("Current index is", currentIndex);
}

goToPrevSlide() {
this.slider.slidePrev(5000, false);
this.slider.slidePrev();
}

goToNextSlide() {
this.slider.slideNext();
}

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

Expand All @@ -50,3 +43,10 @@ class MyApp {
console.log("Current Length is", length);
}
}

@App({
template: `<ion-nav [root]="root"></ion-nav>`
})
class E2EApp {
root: Page = MyPage;
}
10 changes: 5 additions & 5 deletions ionic/components/slides/test/controller/main.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<ion-slides [options]="mySlideOptions" (didChange)="onSlideChanged()">
<ion-slides #mySlider [options]="mySlideOptions" (didChange)="onSlideChanged()">
<ion-slide padding>
<p>Slide 1</p>
<button block (click)="goToSlide(3)">Navigate to 3rd Slide</button>
<h1>Slide 1</h1>
<button block (click)="goToSlide(2)">Navigate to 3rd Slide</button>
<button block (click)="getLength()">Get Slide Length</button>
</ion-slide>
<ion-slide padding>
<p>Slide 2</p>
<h1>Slide 2</h1>
<button block (click)="goToPrevSlide()">Navigate Back</button>
<button block (click)="goToNextSlide()">Navigate Forward</button>
</ion-slide>
<ion-slide padding>
<p>Slide 3</p>
<h1>Slide 3</h1>
<button block (click)="getIndex()">Get Index</button>
</ion-slide>
</ion-slides>

0 comments on commit ee4869a

Please sign in to comment.