question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamically change images and then call the method openPreview but report error

See original GitHub issue

Hi,

Firstly, I mark down ngx-gallery component in html like below, while the variable galleryImages is empty. <ngx-gallery [images]="galleryImagesList" [options]="galleryOptions" #onlyPreviewGalleryHtml></ngx-gallery>

The variable galleryImage and others is defined in typescript file as : public galleryImagesList: NgxGalleryImage[] = new Array<NgxGalleryImage>(); public galleryOptions: NgxGalleryOptions[] = new Array<NgxGalleryOptions>(); @ViewChild('onlyPreviewGalleryHtml') public onlyPreviewGallery: NgxGalleryComponent; ngOnInit(): void { this.galleryOptions.push( { image: false, thumbnails: false, width: ‘0px’, height: ‘0px’ }, { image: false, thumbnails: false, width: ‘0px’, height: ‘0px’, previewZoom: true, previewRotate: true, previewCloseOnClick: true, previewCloseOnEsc: true, previewFullscreen: true, previewKeyboardNavigation: true, previewDescription: true, }, ); }

Secondly, I mark down one button in html, <button (click)=“openPreview()”>open preview</button> and the function openPreview is defined as :

openPreview(): void { this.galleryImagesList.push({ small: ‘assets/tmp/img/1.png’, medium: ‘assets/tmp/img/1.png’, big: ‘assets/tmp/img/1.png’, }); this.galleryImagesList.push({ small: ‘assets/tmp/img/2.png’, medium: ‘assets/tmp/img/2.png’, big: ‘assets/tmp/img/2.png’, });

console.log(this.onlyPreviewGallery.images);

this.onlyPreviewGallery.openPreview(0);

}

so that, you may see I just want to dynamic set the gallery’s images, however, when I first click the button, it report error as below, while you can see the images list is correct.

image

And then I click the button again ,it now worked ! image

so it is quite strange !

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Gurezkiycommented, Dec 18, 2019

Use ChangeDetectorRef before calling openPreview. Example:

@ViewChild('gallery', {static: false}) gallery: NgxGalleryComponent;

constructor(private changeDetectorRefs: ChangeDetectorRef) {
    //******
}

view (url) {
    this.gallery.images = [
      {
        small: url,
        medium: url,
        big: url
      }
    ];
    this.changeDetectorRefs.detectChanges();
    this.gallery.openPreview(0);
}
1reaction
hpawe01commented, Jan 29, 2019

@stringhuang: Sometimes pushing into an existing array behaves weird. Have you tried setting the array in your openPreview method like this?

this.galleryImagesList = [{
    // image1
  }, {
    // image2
  }];

And can you please try to format your code expamples. Would be way easier to read.

Some other code remarks:

  • class variables are public by default (you don’t have to specify this)
  • an instance of a typed array variable will get the correct type implicitly

So you could shorten this: public galleryImagesList: NgxGalleryImage[] = new Array<NgxGalleryImage>(); to this: galleryImagesList: NgxGalleryImage[] = [];

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attach load and error events to dynamic images - Stack Overflow
I am using ADF Faces. In ADF Faces some component loads their children later. So I need to attach the event handler to...
Read more >
Dynamic Images in PowerBI | How to make an ... - YouTube
In this video I will show you how you can introduce a dynamic image in your Power BI dashboard.Watch this video if you...
Read more >
Image Change - L3HarrisGeospatial.com
Image Change Tutorial. The Image Change workflow compares two images of the same geographic extent, taken at different times.
Read more >
Solved: Dynamic image in Report Template - Esri Community
But, when I try to load the template to the survey in survey123.arcgis.com, it raises an error: Erro: An error occurred when checking...
Read more >
Dynamic images won't display in vs2012 ... - SAP Community
I then added a picture object to a report. ... I get no errors and it dynamically displays the correct image when I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found