【问题标题】:Trigger refresh for owl carousel in angular in the package ngx-owl-carousel-ongx-owl-carousel-o 包中的 Angular 猫头鹰轮播触发刷新
【发布时间】:2020-12-28 23:34:19
【问题描述】:

我希望我的 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的刷新

这可能吗?

【问题讨论】:

    标签: javascript angular owl-carousel-2


    【解决方案1】:

    添加您的 ViewChild:

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

    检索您的服务;

       const anyService = this.carousel as any;
       const carouselService = anyService.carouselService as CarouselService;
    
        carouselService.refresh();
        carouselService.update();
    

    【讨论】:

    • 调用刷新后我的轮播消失了
    【解决方案2】:

    根据 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);
    }
    

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

    【讨论】:

      【解决方案3】:

      也一直在寻找这个问题的答案。我的想法是使用@Viewchild 访问元素,然后使用 CarouselService。顺便问一下,你的结局如何? @Anon

      【讨论】:

      • 我最终没有使用旋转木马,但很想为将来的使用找到解决方案。
      • 那么您使用了什么替代方案?我将暂时跳过这方面的工作,但会在几周后回来寻找解决方案。
      猜你喜欢
      • 2018-05-15
      • 2022-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多