[英]Dynamic images with angular and ngx-gallery
我已将ngx-gallery集成到我的项目中。
我的组件现在看起来像这样:
<div class="page-content">
<ngx-gallery [options]="galleryOptions" [images]="galleryImages" fxFlex="70"></ngx-gallery>
<button (click)="updateGallery()">CLICK!</button>
</div>
我正在尝试使用以下功能来更新我的画廊:
updateGallery(): void {
this.galleryImages = this.galleryImagesCache.slice(0, Math.floor(Math.random() * (15 - 1)) + 1);
}
但是,一旦 ngx-gallery 组件被初始化,它就会出现,它不会更新它的内容。 任何建议将不胜感激。
此lib可能只是在OnInit中进行设置,而不处理onChanges。 在github上为此库打开一个问题。
下面是我动态设置 ngx-gallery 图像的方法(你也可以通过 [images] 输入设置初始图像):
HTML:
<div class="page-content">
<ngx-gallery #gallery [options]="galleryOptions"></ngx-gallery>
<button (click)="updateGallery(gallery,images)">show images</button>
</div>
TS:
updateGallery(gallery: NgxGalleryComponent, images) {
gallery.oldImagesLength = 0;
gallery.images = images;
gallery.preview.images = images.map(i => i.big);
gallery.preview.descriptions = new Array<string>().fill(' ', 0, images.length)
gallery.ngOnInit();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.