Slick Carousel with Angular 2

前端 未结 2 1994
星月不相逢
星月不相逢 2020-12-14 08:22

Hi I\'m starting with Angular 2 and trying to make this carousel plugin to work: slick

After a while I managed to make it work like a Component like this:

         


        
相关标签:
2条回答
  • 2020-12-14 09:09

    You should add *ngIf directive to your slick-slider so it is inserted into DOM after data source is populated, in this case it is variable sources:

    <slick-slider *ngIf="sources">
        <div *ngFor="let source of sources">
            <img class="btn btn-lg" (click)="watchSource(source)" src="/assets/img/{{source.name}}.png" />
        </div>
    </slick-slider>
    
    0 讨论(0)
  • 2020-12-14 09:13

    In my case the trick with *ngIf was not enough. Im calling REST service in ngOnInit and receiving response where in subscription I'm defining the array. The only possible workaround for me was to add slick items manually by slick function 'slickAdd' directly from typescript.

    jQuery('.my-slick').slick('slickAdd', '<div><h3>ahoj</h3></div>');
    

    Maybe it will help somebody...

    0 讨论(0)
提交回复
热议问题