ngx-gallery不显示图像

I am using @ngx-gallery/lightbox to display an image gallery. But it does not display any images. This I provide some code and Stackblitz demo as your reference

的HTML

<button mat-button (click)="lightbox.open(0, 'lightbox')">Open Gallery</button>

零件

 items: GalleryItem[];

  constructor(public gallery: Gallery, public lightbox: Lightbox) {

  }
 ngOnInit() {
    // This is for Basic example
    this.items = imageData.map(item => {
      return new ImageItem(item.srcUrl, item.previewUrl);
    });

    // This is for Lightbox example
    this.gallery.ref('lightbox').load(this.items);
  }

}
评论
sunde
sunde

I'm not sure what api u were reading from, but according to their official api, this demo should work

点赞
评论
emagni
emagni

The issue is that the ImageItem class expects a single parameter in form of an object.

这应该可以解决您的问题:

this.items = imageData.map(item => {
      return new ImageItem({ src: item.srcUrl, thumb: item.previewUrl });
    });

点赞
评论
柠萌小姐
柠萌小姐

似乎您尚未正确初始化ImageItem,请尝试此操作

this.items = imageData.map(item => new ImageItem({ src: item.srcUrl, thumb: item.previewUrl }));

代替

this.items = imageData.map(item => {
      return new ImageItem(item.srcUrl, item.previewUrl);
    });

点赞
评论