首页 > 解决方案 > ngx-gallery 不显示图像

问题描述

@ngx-gallery/lightbox用来显示图片库。但它不显示任何图像。我提供了一些代码和Stackblitz演示作为您的参考

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);
  }

}

标签: javascriptangulartypescriptimage-gallery

解决方案


问题是ImageItem该类需要对象形式的单个参数。

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

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


推荐阅读