Home > Software engineering >  Ionic slider onInit never fires
Ionic slider onInit never fires

Time:03-04

I'm using the latest ionic with the slides, which i believe uses Swiper.

I have the swiper options like this:

{
    initialSlide: 0,
    speed: 400,
    onInit: (slides: any) => {
      console.log("SLIDE INIT",slides)
      this.slider = slides
    }

However nothing happens, as though onInit doesn't fire. I have also tried "init" based on the swiper documentation and that also doesn't fire.

What i am trying to do is set the slider to this.slider so i can use the api on it later.

CodePudding user response:

do something like:

import { Component, OnInit, ViewChild, ElementRef, NgZone } from '@angular/core';
import { IonSlides } from '@ionic/angular';

export class YourClass implements OnInit {

  @ViewChild('slides') slides: IonSlides;

  console.log(this.slides); // Now you can access your slide in this.slides

}

in html:

<ion-slides pager="true" [options]="sliderConfig" #slides>
...
</ion-slides>
  • Related