美文网首页程序员
Ionic2-解决在使用slides的时候autoplay、lo

Ionic2-解决在使用slides的时候autoplay、lo

作者: 待花谢花开 | 来源:发表于2017-06-15 08:56 被阅读0次

在我使用ionic提供的最新slides组件的时候,在使用autoplay等属性的时候

    <ion-slides autoplay="3000" loop=true pager=true >
        <ion-slide *ngFor="let slides_image of slides_images" >
            ![]({{slides_image.image}})
        </ion-slide>
    </ion-slides>

遇到以下报错信息:

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

解决方法:
在使用ion-slides的时候加上*ngIf="slides_images.length > 1",判断其长度是否大于1即可。

    <ion-slides autoplay="3000" loop=true pager=true           *ngIf="slides_images.length > 1">
        <ion-slide *ngFor="let slides_image of slides_images" =>
            ![]({{slides_image.image}})
        </ion-slide>
    </ion-slides>

还有部分遇到在页面切换后autoplay失效的问题,只需要加上 autoplayDisableOnInteraction:false即可。

相关文章

网友评论

    本文标题:Ionic2-解决在使用slides的时候autoplay、lo

    本文链接:https://www.haomeiwen.com/subject/zvryqxtx.html