Trouble while loading images from api
See original GitHub issueHello 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…
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.
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.