I am using ion-slides on my home page, but it is not working with autoplay.
Ionic code:
    <ion-slides autoplay=300>
      <ion-slide  *ngFor = "let banners of bannersImage">
        <img src={{banners.image}}>
      </ion-slide>
    </ion-slides>
Error message:
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`
                I have the solution: Do like this
<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>
                        file.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)
        }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With