I have implemented the ngx-slick-carousel
in my Angular project for creating a slider. However, I encountered an error when I navigate to the component containing the slider, resulting in the following error displayed in the console:
ERROR TypeError: _this.$instance.slick is not a function at ngx-slick-carousel.js:121 at ZoneDelegate../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391) at Zone../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:150) at NgZone.push../node_modules/@angular/core/fesm5/core.js.NgZone.runOutsideAngular (core.js:3779) at SlickCarouselComponent.push../node_modules/ngx-slick-carousel/fesm5/ngx-slick-carousel.js.SlickCarouselComponent.initSlick (ngx-slick-carousel.js:114) at SlickCarouselComponent.push../node_modules/ngx-slick-carousel/fesm5/ngx-slick-carousel.js.SlickCarouselComponent.ngAfterViewChecked (ngx-slick-carousel.js:70) at callProviderLifecycles (core.js:9563) at callElementProvidersLifecycles (core.js:9534) at callLifecycleHooksChildrenFirst (core.js:9524) at checkAndUpdateView (core.js:10460)
HTML
<ngx-slick-carousel class="carousel" #slickModal="slick-carousel" [config]="slideConfig2">
<div ngxSlickItem *ngFor="let legislation of objLegislationList" class="slide">
<div class="descBox row-2">
<img
src="http://1.bp.blogspot.com/-Qy1y_Ur-_mE/TtxVJ86z2EI/AAAAAAAAAss/meLIad_uSfk/s1600/law-background-1-767326.jpg" />
<h3 onMouseOver="this.style.cursor='pointer'">{{legislation.Title}}</h3>
<p style="margin-bottom: 0;">Date : {{legislation.Date}}</p>
<p>Category {{legislation.CatName}}</p>
</div>
</div>
</ngx-slick-carousel>
component.ts
ngAfterViewInit() {
this.iniSlickJs();
}
private iniSlickJs() {
const htmlScriptElement = document.createElement('script');
htmlScriptElement.src = 'https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js';
this.elementRef.nativeElement.appendChild(htmlScriptElement);
}