触发ngx-owl-carousel-o软件包中Angular的owl carousel刷新

我希望我的猫头鹰旋转木马使用新的响应选项进行刷新。在jquery中,可以使用以下方法完成: $owl.trigger('refresh.owl.carousel'); 如此处所述:Refresh owl-carousel in Angular(但对于使用jquery作为依赖项的其他插件)。

在api中,提到了refreshClass,但是没有提到触发实例https://www.npmjs.com/package/ngx-owl-carousel-o的刷新

这可能吗?

nut0032 回答:触发ngx-owl-carousel-o软件包中Angular的owl carousel刷新

根据 UberGeoff 的建议,我找到了这个解决方案。

@ViewChild('owlCar',{ static: true }) owlCar: CarouselComponent;

.
.

@HostListener('window:resize',['$event'])
onResize(event) {
    let anyService = this.owlCar as any;
    let carouselService = anyService.carouselService as CarouselService;  
    carouselService.onResize(event.target.innerWidth);
}

不是一个优雅的解决方案,但它有效

,

也一直在寻找答案。我的想法是使用@Viewchild,然后使用CarouselService访问元素。顺便说一句,它到底是怎么做到的? @Anon

,

添加您的ViewChild:

   @ViewChild('carousel',{ static: true }) carousel: CarouselComponent;

获取您的服务;

   const anyService = this.carousel as any;
   const carouselService = anyService.carouselService as CarouselService;

    carouselService.refresh();
    carouselService.update();
本文链接:https://www.f2er.com/2448466.html

大家都在问