bonjurmrfirst / angular4-carousel

Animated angular2/4 carousel
22 stars 13 forks source link

Add support for dynamic input data #16

Closed ryanwoodcox closed 7 years ago

ryanwoodcox commented 7 years ago

Implemented OnChanges to support re-initliazing the component when input properties change. Reference to issue: https://github.com/bonjurmrfirst/angular4-carousel/issues/14

dockleryxk commented 7 years ago

closes #14

bonjurmrfirst commented 7 years ago

Hi, dynamic input data breaks carousel, so I reverted changes. Please let me know if I wrong, but after adding OnChanges, carousel not work properly (images sliding on hover, delay different for images)

ryanwoodcox commented 7 years ago

Is that not something you can fix by reworking the styles? I've done a lot of reworking of the styles to meet my needs, so I am not experiencing this issue.

bonjurmrfirst commented 7 years ago

Moving carousel initialization from OnInit to OnChanges will not work, we should also reset timers and other data related to current carousel instance.

Here is solution works for me to change configs in run-time:

  1. HTML: add *ngIf="enabled" to carousel component. Let enabled variable be true by default.

    <carousel *ngIf="enabled" [sources]="imageSources" [config]="config"></carousel>
  2. TS: add function that reset carousel with new config and/or images.

public enabled = true;

public changeConfig(): void {
    this.enabled = false;

    setTimeout(() => {
      this.imageSources = [
         // new images
      ]

      this.config = {
        // new config
      };

      this.enabled = true;
    });
  }