Ionic2-解决在使用slides的时候autoplay、loop等Input Properties报错问题

在我使用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即可。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 上一节提到几个问题,现在我们逐一来解释一下: 问题一:initSwiper方法为什么放在获取数据之后?它放在其它地...
    IT晴天阅读 4,643评论 13 8
  • 在Ionic开发过程中会遇到很多常见的开发问题,分享一下笔者在开发过程中总结到的对这些问题的解决方案。也是接触io...
    兼续阅读 32,577评论 21 61
  • 今天你从公园 捡回一枚枯叶 它是银杏的叶片 却没了秋的橙黄 小小的叶子卷曲着 像没了糖果的孩子 黯然失色 亲爱的我...
    海兰之芯阅读 2,286评论 0 0
  • 清晨,马不停蹄地叫儿子起床,给他找衣服、袜子,穿好,抱沙发上。做好饭,喂他吃了饭(儿子的吃饭习惯被我彻底惯坏了...
    痴行人阅读 2,744评论 1 1
  • 南方姑娘 晚上看微信推送的一些文章,突然一首南方姑娘入耳。心里突然一颤,呀,我是南方姑娘 嗯~ 我百度了一下,他们...
    女神_经阅读 3,142评论 0 3

友情链接更多精彩内容