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?
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With