离子滑动,在Ionic3中自动播放

vid*_*evi 5 typescript ionic2 ionic3 angular

我在我的主页上使用离子幻灯片,但它不能用于自动播放.

离子代码:

    <ion-slides autoplay=300>
      <ion-slide  *ngFor = "let banners of bannersImage">
        <img src={{banners.image}}>
      </ion-slide>
    </ion-slides>
Run Code Online (Sandbox Code Playgroud)

错误信息:

Uncaught TypeError: Cannot read property 'hasAttribute' of undefined
    at autoplay (main.js:43827)
    at startAutoplay (main.js:43870)
    at initSwiper (main.js:43816)
    at Slides._initSlides (main.js:55290)
    at main.js:55311`enter code here`
Run Code Online (Sandbox Code Playgroud)

小智 5

我有解决方案:这样做

<ion-slides *ngIf="slideData && slideData.length" autoplay="5000" class="slideroption" pager="true"   loop="true" speed="300">
      <ion-slide   *ngFor="let slide of slideData">
                <img src="{{slide.imag}}" />
          </ion-slide>
    </ion-slides>
Run Code Online (Sandbox Code Playgroud)


vid*_*evi 2

文件.ts

 ngAfterViewInit() {  setTimeout(()=>{
         if(this.topProducts && this.topProducts.length > 0){
            this.slides.freeMode = true;
              this.slides.autoplay = 2000;
              this.slides.speed = 500;
              this.slides.loop = true;
              this.slides.startAutoplay()
          }

          },1000)
        }
Run Code Online (Sandbox Code Playgroud)