简体   繁体   English

Ionic 3 幻灯片不适用于自动播放

[英]Ionic 3 slide not working with autoplay

I am using ionic 3.我正在使用离子 3。

Here is my template这是我的模板

 <ion-slides autoplay="5000" loop="true" speed="500" class="slides" pager="true">
      <ion-slide *ngFor="let Image of PImage">
         <img src="{{Image.URL}}" alt="Product Image">
      </ion-slide>
 </ion-slides>

But I am getting this error但我收到这个错误

TypeError: Cannot read property 'hasAttribute' of undefined

How can I fix this issue?我该如何解决这个问题?

Kindly advice me,请给我建议,

Thanks谢谢

There seems to be an issue when trying to create the slides elements, when the data is not ready yet.当数据尚未准备好时,尝试创建幻灯片元素时似乎存在问题 To fix it, use an *ngIf to create the slides only when the data is ready:要修复它,请使用*ngIf仅在数据准备就绪时创建幻灯片:

<ion-slides *ngIf="PImage && PImage.length"  autoplay="5000" loop="true" speed="500" class="slides" pager="true">
      <ion-slide *ngFor="let Image of PImage">
         <img src="{{Image.URL}}" alt="Product Image">
      </ion-slide>
 </ion-slides>

If anyone use Ionic 4, then try this method:如果有人使用 Ionic 4,请尝试以下方法:

HTML: HTML:

  <ion-slides #mySlider (ionSlidesDidLoad)="slidesDidLoad()" autoplay="5000" loop="true" speed="500" class="slides" pager="true" [options]="slideOpts">
    <ion-slide *ngFor="let adsImages of AdsImages">
      <img src="{{adsImages}}">
    </ion-slide>
  </ion-slides>

TS: TS:

  AdsImages = [
    "../../assets/images/ads-sample.webp",
    "../../assets/images/ads-sample2.webp",
    "../../assets/images/ads-sample3.webp"
  ];

  slideOpts = {
    zoom: false
  };

  @ViewChild("mySlider") slides: IonSlides;

  slidesDidLoad() {
    this.slides.startAutoplay();
  }

SCSS: SCSS:

ion-slides {
  --bullet-background: #ffffff;
  --bullet-background-active: #b8b8b8;
}

Fore more information: https://ionicframework.com/docs/api/slides更多信息: https ://ionicframework.com/docs/api/slides

I am using ionic 3.我正在使用离子3。

Here is my template这是我的模板

 <ion-slides autoplay="5000" loop="true" speed="500" class="slides" pager="true">
      <ion-slide *ngFor="let Image of PImage">
         <img src="{{Image.URL}}" alt="Product Image">
      </ion-slide>
 </ion-slides>

But I am getting this error但是我收到这个错误

TypeError: Cannot read property 'hasAttribute' of undefined

How can I fix this issue?如何解决此问题?

Kindly advice me,请告诉我,

Thanks谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM