ionic-framework: [RC5] autoplay property on Slider not working with async data
Edited: Added better description and edited the title.
Ionic version: [ ] 1.x [x] 2.x
I’m submitting a … [x] bug report [ ] feature request [ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/
Current behavior: I recently switched from rc4 to rc5 and I noticed that autoplay is not working. I’m getting the given error:
Runtime Error
Cannot read property 'hasAttribute' of undefined
TypeError: Cannot read property 'hasAttribute' of undefined
at autoplay (http://localhost:8100/build/main.js:45371:20)
at startAutoplay (http://localhost:8100/build/main.js:45409:5)
at initSwiper (http://localhost:8100/build/main.js:45362:9)
at Slides._initSlides (http://localhost:8100/build/main.js:44207:102)
at http://localhost:8100/build/main.js:44227:19
Expected behavior: The slides should slide automatically
Steps to reproduce:
Just add autoplay="2000"
to a <ion-slides>
whose children use the async pipe.
Related code: This is my current slider component configuration
<ion-slides loop="true" autoplay="2300" speed="1000">
<ion-slide *ngFor="let slide of slides | async">
</ion-slide>
</ion-slides>
Other information:
Ionic info:
Ionic Framework: 2.0.0-rc.5
Ionic Native: 2.2.11
Ionic App Scripts: 1.0.0
Angular Core: 2.2.1
Angular Compiler CLI: 2.2.1
Node: 6.9.1
OS Platform: Linux 4.4
Navigator Platform: Linux x86_64
User Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 22 (7 by maintainers)
Hello, Sorry for my English , I found a solution, I know it is not the best but good …
<ion-slides *ngIf=“events” autoplay=“5000” loop=“true”>
</ion-slides>this code works for me , i hope for you too
for my work around, I set the autoplay in page instead.:
in mypage.html
in mypage.ts
I found that if you add a *ngIf=“” checking the length of the slide data source it will work with autoplay and the other attributes that cause it to fail. My slides are loaded asynchronously. This is just a workaround until the core issue with the slider are remedied.
This is what i do to autoplay slider with async data.
@leonardocoutinho Try my solution. It will work.
@rafikhdj you da man!
@mhartington I faced the same issue as @yannbf . I notice when the ion-slide is loaded with async data, an error ( ‘Cannot read property ‘hasAttribute’ of undefined’ ) occured on the input properties like autoplay, loop, etc. When i removed the input properties from ion-slide, it works normal.
<ion-slides [autoplay]="4000" [loop]="true"> <ion-slide *ngFor="let data of slideData"> <img src="{{data.imgPath}}" onerror="src='assets/img/error-image.png'"> </ion-slide> </ion-slides>
Please help solve this issue. Thanks.
@mhartington I noticed the problem is in regards to async data. At first I thought it was just for normal slides, but mine comes from async data.
<ion-slide *ngFor="let slide of slides | async"...>
.It was giving the error
Cannot read property 'hasAttribute' of undefined
because as the slides use async pipe, there are no instances at the moment the page is rendered.Could you please reopen the issue?
Thanks.