代码之家  ›  专栏  ›  技术社区  ›  kamalav

使用jquery swiper实现循环和动态幻灯片内容的角度变化

  •  0
  • kamalav  · 技术社区  · 6 年前

    我必须在角度滑动后更改内容。我在滑动后更改了对象值。但它没有在HTML中重新返回。有谁能帮我实现它。下面是我的jquery swiper事件

       var mySwiper = new Swiper('.swiper-container', {
          direction: 'horizontal',
          loop: true,
          speed: 700,
          replaceState: true,
          initialSlide: 1,
          centeredSlides: true,
          slidesPerView: 'auto',
          loopedSlides: 2,
    
    
          onSlideChangeStart: MoveToNextOrPrevious,
          mousewheelControl: false
        });
    
    
      function MoveToNextOrPrevious() {
      if (mySwiper != undefined) {      
     if (mySwiper.swipeDirection == "next") 
       {   self.Navigate('swiperight');
       }
       }
      }
    

    在导航函数中,我更改了对象值,但在HTML中没有更改

    谢谢,

    1 回复  |  直到 6 年前
        1
  •  1
  •   Patrick angularsen    6 年前

    这很可能与区域有关。进行更改检测时,角度在区域中运行,并且第三方库不会自动在角度区域内运行。

    在构造函数中,可以注入ngzone,然后调用 zone.run 回拨

    constructor(private zone: NgZone) { }
    
    private MoveToNextOrPrevious() {
      this.zone.run(() => { /* your previous code */ });
    }
    

    这应该安排您的代码在角度区域内运行,因此您的更改应该由更改检测接收。

    更详细的解释了 in the docs for NgZone .