How to slide manually to the next slide in ion-slide
Solution 1
Ya, I got the solution. In ionic 4 you have to import IonSlides instead of Slides.
home.ts
import { IonSlides} from '@ionic/angular';
export class HomePage {
@ViewChild('mySlider') slides: IonSlides;
swipeNext(){
this.slides.slideNext();
}
}
home.html
<ion-slides pager="true" pager="false" #mySlider>
<ion-slide>
</ion-slide>
<ion-slide>
</ion-slide>
<ion-button (click)="swipeNext()">Next</ion-button>
</ion-slides>
Solution 2
In Angular 8 :
@ViewChild('mySlider', { static: true }) slides: IonSlides;
Solution 3
Is simple and just necessary in html
<ion-slides #slides pager="true">
<ion-slide>1
</ion-slide>
<ion-slide>2
</ion-slide>
</ion-slides>
<ion-button (click)="slides.slidePrev()" > Prev </ion-button>
<ion-button (click)="slides.slideNext()" > Next </ion-button>
Solution 4
Simple way (same as above answer but I tried to make it simpler):
import { Slides } from 'ionic-angular';
class abc {
@ViewChild(Slides)slides: Slides;
public next(){
this.slides.slideNext();
}
public prev(){
this.slides.slidePrev();
}
}
Related videos on Youtube
Tahseen Quraishi
Experienced Software Engineer with a demonstrated history of working in the information technology and services industry. Skilled in C, C++, Bootstrap, Angular,Javascript,Ionic and flutter. Working experience in platform independent App development and Web development with new technology like Ionic, Flutter, Firebase etc. Strong engineering professional with a Bachelor’s Degree focused in Information Technology from University of RGPV.
Updated on June 04, 2022Comments
-
Tahseen Quraishi almost 2 years
I am using ion-slide in ionic4 and i want to go for next slide manually by clicking on button. I have seen the ion-slide documentation in which they have mention slideNext method. But I don't know how to use this method for changing slide.
-
Alam over 4 yearsHi @Tahseen , Can you elaborate horizontal scroll inside ion-slide Ref. Url
-
Sai Manoj about 4 yearsAny way to slide to last side on click?