Search code examples
ionic-frameworkionic4

ion slider not working in ModalController ionic 4


Version: Cordova: [email protected] Ionic: 6.10.1

Error : this.slider.update is not a function

in .ts

import { ModalController, IonSlides } from "@ionic/angular";

 trainingSliderOpts = {
speed: 400,
initialSlide: 0,
preloadImages: true,
allowTouchMove: false,
 };
result: any;
@ViewChild("trainingSlider", { static: true }) slider: IonSlides;

  ionViewDidEnter() {
this.slider.update();
}

Solution

  • Try to add a .then function at the end like that:

    this.ionSlides.update().then(() =>
            console.log('updated'))
        }
    

    If not working try the following on top of your your class:

     @ViewChild('slider', {read: ElementRef})slider: ElementRef;
    

    and then call it like this:

    this.slider.nativeElement.update();