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.

Trouble while loading images from api

See original GitHub issue

Hello i have trouble while loading images…

This is how i do it

  imagesRect: Image[] = [
    new Image(
      0,
      {
        img: '',
      },
      {
        img: '',
      }
    ),
  ];

    this.apiService.findProduct().subscribe(
      res => {
        const images: Image[] = [];
        for(let i=0;i<res?.productImages.length;i++){
          images.push(
            new Image(
              i,
              {
                img: 'http://localhost:8080/product/image/'+res.product.title+'/'+res.productImages[i].image,
              },
              {
                img: 'http://localhost:8080/product/image/'+res.product.title+'/'+res.productImages[i].image,
              }
            ),
          )
        }
        this.imagesRect=images;
      }

so when images are not loaded and i click on arrow images got loaded. also when i click on empty image like on screenshot bellow, images are present in modal gallery But loading on main page is way too slow…

image

video : https://www.youtube.com/watch?v=Bb7tUbGpfeU

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Ks89commented, Oct 26, 2020

@hvsharma63

I suggest to hide the carousel when the array is empty with an *ngIf=“show” or *ngIf=“arrayofImages.length === 0”. When the rest api returns data, in the subscribe(…) you can init the show variable or add the elements into arrayofImages. In this way, the carousel will be visible with your images. You could also display a custom spinner when show = false or arrayofImages.length === 0 to improve UX.

1reaction
Ks89commented, Aug 22, 2020

No no wait I can’t understand your problem in this way 😃.

Your original problem was about how to update the array. The first answer should fix it.

However, your next comment is about an error when you start the carousel without images in the array. Is it right? You can’t show a carousel without images. I suggest to hide the carousel when the array is empty with an *ngIf=“show”. show starts as false and it becomes true inside the subscribe of findProduct(). In this way, it should work. You could also display a spinner when show = false to improve UX.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to handle loading of images that may not exist?
How to handle loading of images that may not exist? · 1. Periodic data cleanup · 2. Handle it in your application ·...
Read more >
Unable to show a loading image while the rest api call is ...
I use StackOverflow to give my students programming assignments and have them optimize code. Note! They usually do not test the code, ...
Read more >
Images load on localhost, but not loading when deployed to ...
I have a Js file that loads images into my web app. When I test it on localhost, it loads the images just...
Read more >
You are loading Images wrong! Use this instead - YouTube
As developers, we have to deal a lot with images, from blogs to landing pages, it's all about giving the users the best...
Read more >
Browser-level image lazy loading for the web - web.dev
This post covers the loading attribute and how it can be used to control the loading of images.
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