[英]ngx-gallery not displaying image
I am using @ngx-gallery/lightbox
to display an image gallery.我正在使用
@ngx-gallery/lightbox
来显示图片库。 But it does not display any images.但它不显示任何图像。 This I provide some code and Stackblitz demo as your reference
我提供了一些代码和Stackblitz演示作为您的参考
HTML HTML
<button mat-button (click)="lightbox.open(0, 'lightbox')">Open Gallery</button>
Component零件
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);
}
}
The issue is that the ImageItem
class expects a single parameter in form of an object.问题是
ImageItem
class 需要一个 object 形式的参数。
This should fix your issue:这应该可以解决您的问题:
this.items = imageData.map(item => {
return new ImageItem({ src: item.srcUrl, thumb: item.previewUrl });
});
Seems like you have not initialised ImageItem properly, try this好像你没有正确初始化 ImageItem,试试这个
this.items = imageData.map(item => new ImageItem({ src: item.srcUrl, thumb: item.previewUrl }));
instead of代替
this.items = imageData.map(item => {
return new ImageItem(item.srcUrl, item.previewUrl);
});
I'm not sure what api u were reading from, but according to their official api , this demo should work我不确定 api 你读的是什么,但根据他们的官方 api ,这个演示应该有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.