0

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

<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
4

1 回答 1

6

在你的 .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>
于 2019-08-08T10:48:57.770 回答