leo6104 / ngx-slick-carousel

Angular 17+ wrapper for slick plugin
102 stars 37 forks source link

Inside angular material tab first time it's working if I am changing the tab and coming back again then width is increasing it's not initializing properly #34

Open Amitshaale opened 4 years ago

Amitshaale commented 4 years ago

Hi,

Please help... I have puted slider inside tab and it's working fine for first time, if I go to some other tab and coming again to slider tab it's not working properly.

Here is my code...

// HTML <ngx-slick-carousel class="carousel"

slickModal="slick-carousel"

                    [config]="slideConfig" 
                    (init)="slickInit($event)"
                    (breakpoint)="breakpoint($event)"
                    (afterChange)="afterChange($event)"
                    (beforeChange)="beforeChange($event)">
    <div ngxSlickItem *ngFor="let slide of slides" class="slide">
          <img src="{{ slide.img }}" alt="" width="100%">
    </div>

// Component.ts

slides = [ { img: 'http://placehold.it/350x150/000000' }, { img: 'http://placehold.it/350x150/111111' }, { img: 'http://placehold.it/350x150/666666' }, { img: 'http://placehold.it/350x150/333333' }, { img: 'http://placehold.it/350x150/666666' }, { img: 'http://placehold.it/350x150/666666' } ]; slideConfig = { slidesToShow: 4, slidesToScroll: 4, infinite: false };

addSlide() { this.slides.push({ img: 'http://placehold.it/350x150/777777' }); }

removeSlide() { this.slides.length = this.slides.length - 1; }

slickInit(e) { console.log('slick initialized'); }

breakpoint(e) { console.log('breakpoint'); }

afterChange(e) { console.log('afterChange'); }

beforeChange(e) { console.log('beforeChange'); }

filol commented 4 years ago

Not only in material tab, i have the problem on a basic page

kalathiyan commented 4 years ago

+1 facing same issue, anyone found solution ?

bhargav-spinx commented 3 years ago

facing the same issue, did anyone found the solution?

rajeevudayan1 commented 2 years ago

Facing the same issue. Any solution?

Kanaan95 commented 1 year ago

You can try using the slickGoTo() method in the AfterViewInit lifecycle.

If this doesn't work, here's something I did, and it works. Set the variableWidth property to true on init, then in the AfterViewInit, set it back to false.

Hope this helps