Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slick-cloned slides are not tracked by angular #68

Open
rerion opened this issue Dec 4, 2020 · 1 comment
Open

Slick-cloned slides are not tracked by angular #68

rerion opened this issue Dec 4, 2020 · 1 comment

Comments

@rerion
Copy link

rerion commented Dec 4, 2020

related to #31 #18

When using infinite mode, some slides are cloned.
These cloned slides don't have instances of directives/components attached to appropriate elements.
That's probably because slick itself handles cloning of slides, and it clones only DOM nodes, not angular instances.

This causes problems with any dynamic changes to slides.

See stackblitz:
https://stackblitz.com/edit/angular-chf3v8

Original carousel items are changed by code inside CarouselItemComponent, cloned slides are not.

@nishanc
Copy link

nishanc commented Dec 8, 2023

This is what I use as a workaround.

afterChange(changeEvent: any) {
    const elements = changeEvent.event.target.lastElementChild.firstChild.getElementsByClassName('slick-cloned') as HTMLElement[];
    for (const element of elements) {
      if(!element.classList.contains('listen')){
        element.classList.add('listen')
        element.addEventListener('click', (clickEvent: any) => {
          // Navigation logic here
        });
      }
    }
  }

Add (afterChange) to template

<ngx-slick-carousel
      class="carousel"
      #slickModal="slick-carousel"
      (afterChange)="afterChange($event)"
      [config]="marqueeConfig"
>

Based on anelad's comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants