Git Product home page Git Product logo

Comments (10)

depiction avatar depiction commented on June 26, 2024 1

@Feof In my application I get this error if a user tries to navigate to another view (regardless of whether or not the new view has a carousel or not) before slide data has been received.

The following code worked for me.

I'm getting slide data from an API in the parent component. Once a response from the API has been received, I set loaded to true and pass the slides array to my carousel component.

<ng-container *ngIf="loaded else loading">
    <app-carousel [slides]="slides" *ngIf="(slides && slides.length)"></app-carousel>
</ng-container>

from ngx-slick.

iphilippenko avatar iphilippenko commented on June 26, 2024

the same for me

from ngx-slick.

oveshparasara avatar oveshparasara commented on June 26, 2024

ngx-slick.umd.js In which there are two code blocks:
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)

from ngx-slick.

depiction avatar depiction commented on June 26, 2024

This is a duplicate of #6

You can use the ngIf structural directive to only include the element or component containing the carousel if there is at least one slide.

from ngx-slick.

vgflutter avatar vgflutter commented on June 26, 2024

depiction:you answer always same. The problem born when leave a view that has a slide for a new view. Do you explain me how I should use that ngif?

I have a template:

  <a [routerLink]="['/event', 3]">bye bye</a>
  <div class="card">
    <h5 class="card-header">..</h5>
    <div class="card-block">
      <ngx-slick *ngIf="slides && slides.length" class="carousel" #slickModal="slick-modal" [config]="slideConfig">
        <div ngxSlickItem *ngFor="let slide of slides[0]" class="slide">
          ..
        </div>
      </ngx-slick>
    </div>
  </div>

If a click on element a, it crash.

from ngx-slick.

vgflutter avatar vgflutter commented on June 26, 2024

Your context is very specific.
All persons, except you, have my same problem.
Tomorrow I see the source code.
Is app-carousel a directive ?
I do not know why you do not have this problem

from ngx-slick.

depiction avatar depiction commented on June 26, 2024

app-carousel is a component.

When creating a component using the Angular CLI, the component's selector, by default, is always "app-[component-name]".

Feel free to try my technique, which requires moving the carousel to a separate component.

from ngx-slick.

vgflutter avatar vgflutter commented on June 26, 2024

Also I have a separate component. I have </ component> and inside ngx-slick. you use that slides, I do not know what to do. However, I think the author left the project.

from ngx-slick.

emmahoggan avatar emmahoggan commented on June 26, 2024

I'm using the slider inside of a modal that may or may not be opened, and I get the error when navigating if the modal was never opened, so there are some unique factors. Preferably, the library would be changed to null check before calling unslick. But I got around it for now with this kludge-y bit of code:

` ngAfterContentInit() {

	if (this.isVisible) {
		this.ngxSlick.initSlick();
	}
	else {
		this.ngxSlick.$instance = {};
		this.ngxSlick.$instance.slick = (input) => { };
	}
}`

from ngx-slick.

devmark avatar devmark commented on June 26, 2024

Closed. open new issue if any question.

from ngx-slick.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.