Ion-slides - lockSwipes - has something changed?


#1

What is the current way to lockSwipes on ion-slides?

<ion-slides lockSwipes="true"> - does not work.

The following does not work either - errors with: Cannot read property ‘lockSwipes’ of undefined

ionViewDidLoad() {
        this.slides.lockSwipes(true);
    }
ionViewDidEnter(){
        this.slides.lockSwipes(true);
    }

I have tried adding: @ViewChild(Slides) slides: Slides;
…with no success.

Although, if I call lockSwipes after a button click, it works.

next() {
        this.boxSlider.slideNext();
        this.boxSlider.lockSwipes(true);
    }

Now it is locked.


#2

i think it is

this.slides.onlyExternal = true


#3

Unfortunately, that gives me the same error: Cannot set property ‘onlyExternal’ of undefined
I put it in ionViewDidLoad.
So, it is not recognizing the ion-slides component until after it is swiped or advanced.


#4

i “configure” my slides in the ngOnInit livecycle hook. you may try this.
do you have some ngIf which depends on an async call or something like that?
at the end you can always try to setTimeout until your slides are initialized :slight_smile:


#5

setTimeout did not work but you are right on the money with *ngIf
Not totally proven out yet but I’m pretty sure that is what it must be - thanks - great lead!


#6

It was ion-segment that was killing it.
Now I call this.boxSlider.lockSwipes(true); on segment change but I had to do a setTimeout on it anyways.

onSegmentChange(cur_segment) {
        if (cur_segment == "details_segment") {
            //this.boxSlider.onlyExternal = true; //did not work
            //this.boxSlider.lockSwipes(true); //didn't work

            setTimeout(() => {
                this.boxSlider.onlyExternal = true; //works
                this.boxSlider.lockSwipes(true); //works
            }, 500);

        }
    }