slick转盘在angular2的*ngFor指令中不工作
Slick carousel正在处理静态数据。但如果我使用*ngFor重复这些项,但它不起作用。我已经尝试了所有生命周期挂钩(AfterContentInit、AfterViewInit、AfterViewChecked),请帮助slick转盘在angular2的*ngFor指令中不工作,angular,async-await,carousel,slick.js,Angular,Async Await,Carousel,Slick.js,Slick carousel正在处理静态数据。但如果我使用*ngFor重复这些项,但它不起作用。我已经尝试了所有生命周期挂钩(AfterContentInit、AfterViewInit、AfterViewChecked),请帮助 导入{ 组件,OnInit } 从“@angular/core”开始; 声明 让jQuery:any; 进口“光滑转盘”; @ 组成部分({ 选择器:“应用程序滑块”, templateUrl:'./slider.component.html', styleUrls
导入{
组件,OnInit
}
从“@angular/core”开始;
声明
让jQuery:any;
进口“光滑转盘”;
@
组成部分({
选择器:“应用程序滑块”,
templateUrl:'./slider.component.html',
styleUrls:['./slider.component.less']
})
导出类SliderComponent实现OnInit{
构造函数(){}
恩戈尼尼特(){
jQuery(“.slider”).slick({
点:错,
箭头:是的,
幻灯片放映:6
})
}
我使用了setTimeout()
其中initCarousel()包含
这对我来说很好。
完整代码:
this.api.getAllProducts()
.pipe(map(actions => actions.map(a => {
const data = a.payload.doc.data();
const did = a.payload.doc.id;
return {did, ...data};
})))
.subscribe(res =>{
this.products = res;
if(this.products.length > 0)
setTimeout( ()=>{
this.initCarousel();
this.showProduct = true;
}, 1000);
});
“不工作”是什么意思?有错误吗?滑块没有被应用。如果我一次给出10个图像,所有图像都会被显示。我需要显示6个图像,然后在滑动后,我需要显示剩余的图像使用此超时对我有效。但是有一个更好的方法来处理这种情况,使用unslick()函数。如果有人知道该方法,请更新。
$(".slider").slick({
// normal options...
infinite: true,
dots: true,
arrows: true,
autoplay: true,
slidesToShow: 5,
slidesToScroll: 5,
// the magic
responsive: [
{
breakpoint: 1200,
settings: {
arrows: true,
slidesToShow: 4,
slidesToScroll: 4
}
},
{
breakpoint: 1024,
settings: {
slidesToShow: 3,
infinite: true
}
}, {
breakpoint: 600,
settings: {
slidesToShow: 2,
dots: true
}
}, {
breakpoint: 300,
settings: "unslick" // destroys slick
}]
});
this.api.getAllProducts()
.pipe(map(actions => actions.map(a => {
const data = a.payload.doc.data();
const did = a.payload.doc.id;
return {did, ...data};
})))
.subscribe(res =>{
this.products = res;
if(this.products.length > 0)
setTimeout( ()=>{
this.initCarousel();
this.showProduct = true;
}, 1000);
});