Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2 Slides Component - How to Access Swiper API

Using ion-slides component (4 slides) on app welcome page/slides. I need ability for user to skip to last slide. Docs say ion-slides implementation of Swiper API. I need to access methods like: mySwiper.slideTo(index, speed, runCallbacks);

Tips on how to implement?

like image 278
Steve Harbick Avatar asked Mar 02 '16 06:03

Steve Harbick


2 Answers

You can pass a function within the options property.

Original answer.

@Component({
  selector: 'my-component',
  template: '<ion-slides [options]="options">
               <ion-slide>Slide1</ion-slide>
               <ion-slide>Slide2</ion-slide>
             </ion-slides>',
  directive: [IONIC_DIRECTIVES]
})
export class MyComponent {
  public slider: any;

  constructor() {
    this.options = {
      onlyExternal: false,
      onInit: (slides: any) =>
        this.slider = slides
    }
  }

  click() {
    this.slider.sliderNext(true, 250);
  }
}

For further options have a look at the swiper api.

like image 116
Flow Avatar answered Oct 14 '22 07:10

Flow


If you are looking for a simple solution without custom directives, you can try this

  constructor(
    private _app: IonicApp
  ){}
  ngAfterViewInit() {
    this._slider = this._app.getComponent('my-slider');
  }
  goToSlide(slideIndex){
    this.slider.slider.slideTo(slideIndex);
  }
like image 39
Jai Krishnan Avatar answered Oct 14 '22 07:10

Jai Krishnan