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

Cannot read property 'slick' of undefined #6

Closed
snaik2064 opened this issue Jul 18, 2017 · 15 comments
Closed

Cannot read property 'slick' of undefined #6

snaik2064 opened this issue Jul 18, 2017 · 15 comments

Comments

@snaik2064
Copy link

I am currently using ngx-slick@0.1.1 & angular version 4.2. After any router navigation i am getting this error

Uncaught (in promise): TypeError: Cannot read property 'slick' of undefined
TypeError: Cannot read property 'slick' of undefined.

& getting this console

removeSlide SlickItemDirective {el: ElementRef, carousel: SlickComponent}

Because of this error our projects navigation fails although slick is working fine. So is there any configuration to solve this error?

@snaik2064 snaik2064 changed the title Cannot read property 'slick' of undifined Cannot read property 'slick' of undefined Jul 18, 2017
@Taewa
Copy link

Taewa commented Sep 25, 2017

@snaik2064 @devmark
Having same issue. Did you resolve it?

@Taewa
Copy link

Taewa commented Sep 25, 2017

Just a quick and probably not appropriate solution but working.

in ngx-slick folder, open index.js and find SlickComponent.prototype.unslick...
inside of this method, comment _this.$instance.slick('unslick');
Then you are able to navigate.

@devmark Please let us know how can we fix this issue.

Thanks.

Taewa pushed a commit to Taewa/ngx-slick that referenced this issue Sep 26, 2017
@snaik2064
Copy link
Author

snaik2064 commented Sep 28, 2017

@devmark @Taewa I am able to resolve this issue. The actual problem is inside

ngx-slick.umd.js In which there are two code blocks:
1.

`SlickComponent.prototype.ngOnDestroy = function () {
        this.unslick();
    };`
SlickItemDirective.prototype.ngOnDestroy = function () {
        this.carousel.removeSlide(this);

so the real problem is if we are using "slick" inside OneComponent and then we are navigating to TwoComponent, then due to routing OneComponent get destroys along with our "slick" configuration variable.
And after that our "slick" library runs above two blocks which need component's slick configuration, which is not available because it's already destroyed and we get mentioned error.(Cannot read property 'slick' of undefined)

By commenting those both blocks you can achieve successful routing.(Not Recommended for live project)
Because this changes are inside node_modules so it should be made by ngx-slick package author in next version.

@gabosvk
Copy link

gabosvk commented Oct 12, 2017

+1 - waiting for fix to be implemented....

2 similar comments
@elic28
Copy link

elic28 commented Oct 23, 2017

+1 - waiting for fix to be implemented....

@gabosvk
Copy link

gabosvk commented Oct 29, 2017

+1 - waiting for fix to be implemented....

@gabosvk
Copy link

gabosvk commented Oct 29, 2017

Just adding my observation - I'm using webpack with my angular2 app and the workaround steps @snaik2064 mentioned in his answer needed to be commented out not in ngx-slick.umd.js but in index.js in the same directory. Maybe lame but I was struggling with this for couple of hours couldn't understand why the "commented out" parts are still used...

@snaik2064
Copy link
Author

@gabosvk I have implemented Angular 4 project with systemJS, so there might be a difference between implementation of webpack and systemJS. So ngx-slick.umd.js solution works for me. I will also try your solution whether it works for me or not.

But whether it's ngx-slick.umd.js or index.js , this correction should be done inside this repo so everyone's bug will get resolved.

@depiction
Copy link

Since this only occurs when there are no slides, you can use the ngIf structural directive to only include the element or component containing the carousel if there is at least one slide.

<app-carousel [slides]="slides" *ngIf="slides.length"></app-carousel>

@vgflutter
Copy link

depiction, I leave a view that has a ngx-slick for a new view that hasn't slide.
I don't understand your comment.
for the author:
do you want to fix this bug??!?!?!

@devmark
Copy link
Owner

devmark commented Jul 11, 2018

Closed. open new issue if any question.

@devmark devmark closed this as completed Jul 11, 2018
@polaris327
Copy link

@devmark Why closed? Is that fixed???

@arun-maddheshia
Copy link

arun-maddheshia commented Jul 28, 2018

@devmark please reopen i still getting this error or provide some documentation to fix let get out of this issue

ERROR TypeError: _this.$instance.slick is not a function
    at ngx-slick.umd.js:78
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:138)
    at NgZone.push../node_modules/@angular/core/esm5/core.js.NgZone.runOutsideAngular (core.js:4708)
    at SlickComponent.push../node_modules/ngx-slick/ngx-slick.umd.js.SlickComponent.initSlick (ngx-slick.umd.js:70)
    at SlickComponent.push../node_modules/ngx-slick/ngx-slick.umd.js.SlickComponent.addSlide (ngx-slick.umd.js:113)
    at SlickItemDirective.push../node_modules/ngx-slick/ngx-slick.umd.js.SlickItemDirective.ngAfterViewInit (ngx-slick.umd.js:256)
    at callProviderLifecycles (core.js:12748)
    at callElementProvidersLifecycles (core.js:12715)
    at callLifecycleHooksChildrenFirst (core.js:12698)

@alfredorico
Copy link

alfredorico commented Aug 10, 2018

Same issue from here. Please reopen!

ERROR TypeError: "_this.$instance.slick is not a function" initSlickwebpack-internal:///./node_modules/ngx-slick/ngx-slick.umd.js:78:13invokewebpack-internal:///./node_modules/zone.js/dist/zone.js:388:17runwebpack-internal:///./node_modules/zone.js/dist/zone.js:138:24node_modulesangular/core/esm5/core.js:4913:54initSlickwebpack-internal:///./node_modules/ngx-slick/ngx-slick.umd.js:70:9addSlidewebpack-internal:///./node_modules/ngx-slick/ngx-slick.umd.js:113:13ngAfterViewInitwebpack-internal:///./node_modules/ngx-slick/ngx-slick.umd.js:256:9

@miguelcamposdev
Copy link

Someone has the solution for this warning??? I'm trying to use the ViewChild to control next and prev slides and I get this warning:

ERROR TypeError: Cannot read property 'slickNext' of undefined

I have defined:

@ViewChild('slickModal', {static: true}) public slickModal: SlickCarouselComponent;
and this is my HTML:

<ngx-slick-carousel #slickModal="slick-carousel" [config]="slideConfig">

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