Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ion-slides with auto play in Ionic3

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`
like image 853
vidya devi Avatar asked May 19 '17 05:05

vidya devi


2 Answers

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>
like image 56
Sayan Samanta Avatar answered Nov 24 '22 02:11

Sayan Samanta


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)
        }
like image 29
vidya devi Avatar answered Nov 24 '22 03:11

vidya devi