-1

I can view my image from direct URL apply in src tag but if I tried load as dynamically it's throwing error. I tried [src]="img.ImagePath" this method also I'm getting same response

Console log. Error

HTML

<div *ngFor="let img of imageData">
   <img [alt]="img.Name" src="{{img.ImagePath}}}">
</div>

component.ts

 getImages() {
   this.image.getImage().subscribe(res => {
   this.imageData = res;
    console.log(res);
 });
}

service.ts

  getImage() {
    return this.http.get('https://localhost:44349/api/second?id=2');
  }

My API run in https://localhost:44349/ and my angular application is running in http://localhost:4200/

valdimar
  • 3
  • 4

3 Answers3

0

Depending on how you have set up change detection it could be that your component is not being marked for check.

A better idea for handling asynchronous data with templates is to use the async pipe in the template

HTML

<div *ngFor="let img of (image.getImage() | async)">
  <img [alt]="img.Name" src="{{img.ImagePath}}}">
</div>

This will handle subscription and more importantly clean-up. More reading:

Calummm
  • 819
  • 1
  • 8
  • 21
0

I just changes image URL to my API like below

 <img src="https://localhost:44349/{{img.ImagePath}}">

Is it safe if I sue like this?

valdimar
  • 3
  • 4
-1

Hi,

First thing, you should check for the path comming from the response.

Second thing, if path for the images in response, then that image must be there in specified folder , here I think you have Images folder

Third thing, showing 404 means you should check folder structure for image path where it resides and then check again, it will work>

sda87
  • 372
  • 3
  • 10