leo6104 / ngx-slick-carousel

Angular 17+ wrapper for slick plugin
113 stars 45 forks source link

data-slick-index is wrong after dynamically changing slides #21

Open botoxparty opened 5 years ago

botoxparty commented 5 years ago

Hi,

I am using 2 sliders, a nav and a main slider. When changing the slides dynamically the data-slick-index is incorrect.

To solve this problem currently I am re-assigning the indexes with a setTimeout to wait for slick to finish its business first.

          setTimeout(() => {
            if (!fresh) {
              const list = document.querySelector('.slider-nav');
              let elements = list.querySelectorAll('.ng-star-inserted');

              console.log(elements);

              for (var i = 0; i < elements.length; i++) {
                elements[i].setAttribute('data-slick-index', i.toString());
              }
            }
        }, 50);