metafizzy / flickity

:leaves: Touch, responsive, flickable carousels
https://flickity.metafizzy.co
7.52k stars 605 forks source link

Error parsing data-flickity on carousel: SyntaxError: Unexpected token o in JSON at position 1 #805

Closed cgilbe27 closed 6 years ago

cgilbe27 commented 6 years ago

<flickity class="lifestyleFlick" *ngIf="imageSet" [images]="imageSet" [options]="flickityOptions"></flickity> Being called on the component through a directive(which is where the error comes from)

typescript of directive


import { AfterViewInit, Component, Inject, Input, PLATFORM_ID, ViewChild } from "@angular/core";
declare const Flickity: any;

@Component({
  selector: "flickity",
  templateUrl: "./flickity.component.html",
})
export class FlickityComponent implements AfterViewInit {
  @Input() public images: string[] = [];
  @Input() public options = { wrapAround: true, autoPlay: 5000, imagesLoaded: true }; // Default options
  @ViewChild("flickity") public flickity: any;

  constructor(@Inject(PLATFORM_ID) private platformId: object) { }

  public ngAfterViewInit() {
    if (isPlatformBrowser(this.platformId)) {
      this.flickity = new Flickity(".carousel", this.options);
    }
  }
}```

HTML of directive
```<div class="carousel" [attr.data-flickity]="options" #flickity>
  <div *ngFor="let image of images" class="carousel-cell">
    <img src="{{image}}" class="carousel-image" />
  </div>
</div>```
desandro commented 6 years ago

If you're using flickity with Angular I recommend using a proper directive for Flickity like angular-flickity