ionic4 滑动到下一个

ionic4 slide to next

我想手动移动到下一张幻灯片,但出现错误。 我试过这样:

<ion-slides #sliderRef pager="true" (ionSlideWillChange)="onSlideChangeStart($event)">
<ion-button (click)="slideNext()">Next</ion-button>

在 ts 文件中:

import { Component, OnInit,  ViewChildren, ElementRef } from '@angular/core';
import { IonSlides } from '@ionic/angular';

export class AppointmentPage implements OnInit {
    @ViewChild('sliderRef', { static: true }) protected slides: ElementRef<IonSlides>;

constructor(){}

    async slideNext(): Promise<void> {
         await this.slides.nativeElement.slideNext();
    }
...
}

通过调用 slideNext() 我遇到了这个错误:

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'slideNext' of undefined

在你的 .ts 中

moveToNext(slides){
    console.log(slides);
    slides.slideNext()
}

在你的html

   <ion-slides pager="true" #theSlides>
        <ion-slide >
         <ion-button (click)="moveToNext(theSlides)">Click to go to next</ion-button>   // user click event to go to next slide    
        </ion-slide>
       <ion-slide >
         <ion-button (click)="moveToNext(theSlides)">Click to go to next</ion-button>   // user click event to go to next slide    
        </ion-slide>
     </ion-slides>