Angular2+/Angular7 + Swiper
1.Angular加载很多插件都需要放在afterViewinit
等视图渲染完毕之后再调用.
2.本次使用Swiper也不例外.
3.使用的时候发现loop有时候好使有时候不好使,由于html页面的数据是用ngfor
来做的,后来感觉到应该是网速的问题导致了Swiper的错乱.比如说我的.
<div *ngFor="let article of recommendArticle" class="swiper-slide">
<img [src]="article.coverUrl" alt="">
{{article.intro}}
</div>
我想让Swiper既循环滚动又能自动播放…
observer: true,
observeParents: true,
首先这俩参数是必须要写的,原理不知道.
其实原来出现了滑动失效的问题,后来百度查了需要setTimeout里对swiper进行配置,应该是和angular的生命周期有关.
loop还是不好使.不知道为什么,所以这里把他放在了向后端请求数据成功之后再进行swiper的初始化.
结果还尼玛不行.快给我气死.
this.articleService.getArtcle.suscribe(value => {
let myswiper = ....;
}
)
这样写还是不行,再改成这样.
this.articleService.getArtcle.suscribe(value => {
setTimeout(() => {
let myswiper = ....;
})
}
)
完美…