Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML not getting updated after adding new elements in galleryItems #1585

Closed
himanshi-proximous opened this issue Jan 17, 2024 · 2 comments
Closed
Labels

Comments

@himanshi-proximous
Copy link

Description

I am adding new images using refresh method, it is updating my galleryItems in lightGallery but not adding the html for new items

Steps to reproduce

image

JS code that you use to initialize lightGallery.

this is the function I am calling from a parent component in angular:
updateGallery(lightGallery: LightGallery): void {
this.dataArray = this.dataService.getArray();

const galleryItems = this.dataArray.map((src: any, index: number) => ({
  src: src.fileUrl,         
  downloadUrl: src.downloadUrl,
  thumb: src.thumbUrl,     
  alt: src.mime_type, 
}));

this.images = [
  ...this.images,
  galleryItems
];

this.lightGallery = lightGallery;
this.lightGallery.refresh(galleryItems);

}

@bytesandbots3
Copy link
Contributor

@himanshi-proximous , Based on the given code, it seems that you are trying to update the gallery by adding new images using the refresh method. However, it appears that the HTML is not getting updated with the new items.

One possible reason for this issue could be that you are not updating the this.images array correctly. In the code snippet you provided, you are spreading the galleryItems array inside another array when updating this.images. This will result in a nested array structure, which might not be handled correctly by the HTML rendering.

To fix this issue, you can update the this.images array directly with the new galleryItems array, without spreading it inside another array. Here's an updated version of your code:

updateGallery(lightGallery: LightGallery): void {
  this.dataArray = this.dataService.getArray();

  const galleryItems = this.dataArray.map((src: any, index: number) => ({
    src: src.fileUrl,         
    downloadUrl: src.downloadUrl,
    thumb: src.thumbUrl,     
    alt: src.mime_type, 
  }));

  this.images = [
    ...this.images,
    ...galleryItems
  ];

  this.lightGallery = lightGallery;
  this.lightGallery.refresh(this.images);
}

By updating this.images with the new galleryItems array directly, the HTML should now be updated correctly when calling the refresh method.

I hope this helps!

Copy link

stale bot commented Apr 16, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the v1 label Apr 16, 2024
@stale stale bot closed this as completed May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants