Ion-slides - lockSwipes - has something changed?

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() {

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

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

next() {

Now it is locked.

i think it is

this.slides.onlyExternal = true

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.

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:

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!

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);

1 Like