我有个主意。我希望它对你有帮助。
模板
<ion-slides #slides (ionSlideTouchEnd)=ionSlideTouchEnd($event)>
<ion-slide class="slide-item" *ngFor="let item of items; index as index;" (click)="onClickSlide(index)">
<ion-button [ngClass]="{'active': activeIndex === index}">{{item.title}}</ion-button>
</ion-slide>
</ion-slides>
TS文件
import { IonSlides } from '@ionic/angular';
...
@ViewChild('slides', { read: IonSlides }) slides: IonSlides;
activeIndex: number = 0;
items = [
{
id: 1,
title: 'Item 1'
},
{
id: 2,
title: 'Item 2'
},
{
id: 3,
title: 'Item 3'
}
];
...
onClickSlide(id) {
this.activeIndex = id;
}
// Emitted when the user releases the touch.
ionSlideTouchEnd(){
// Lock the ability to slide to the next or previous slide.
this.slides.lockSwipes(true);
}
样式文件
.active {
// style to detect the active slide
}