Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the instance of a ion-slides

Tags:

angular

ionic2

I am using Ionic 2 ion-slides, and would like to call some instance methods on it. I have the following markup:

<ion-content padding>
  <ion-slides (ionDidChange)="onSlideChanged($event)" id="loopSlider">
   <ion-slide *ngFor="let slide of slides">
    <h1>{{ slide.title }}</h1>
  </ion-slide>
</ion-slides>
</ion-content>

I have tried using the following code I found in a (perhaps outdated) example:

 private gotoSlide(index: number): void {
   this.sliderComponent = this.app.getComponent('loopSlider');
   this.sliderComponent.slider.slideTo(index);
  }

but this.app.getComponent('loopSlider'); always returns null.

Does anyone know how to get the component instance so I can use its API?

like image 217
peterc Avatar asked Aug 06 '16 07:08

peterc


People also ask

How do you make an ionic slider?

Creating. You should use a template to create slides and listen to slide events. The template should contain the slide container, an <ion-slides> element, and any number of Slide components, written as <ion-slide> . Basic configuration values can be set as input properties, which are listed below.


1 Answers

Now that Ionic4 has been out for a while it's probably frugal to update answers like this, for it.

import { IonSlides } from '@ionic/angular';

export class...
@ViewChild(IonSlides) productSlider: IonSlides;
like image 145
Grant Avatar answered Oct 07 '22 10:10

Grant