Reputation: 940
I am trying to bind the img url from api response. Here I have attached what I have tried so far.
Json data structure :
This is the structure of data I received from API
my-cart.component.ts
this.CartdataService.get_Product_Details(this.productCode).subscribe(
data => {
this.productDetails = data;
this.productImages = this.productDetails['0']['PROD_B']
console.log(this.productImages);
});
Receiving array of data in console
Here console I got the image url in an array.
HTML code
<img *ngFor="let images of productImages; let i = index" (mouseenter)="mouseEnter($event)" [src]="images['PRODUCT_THUMBNAIL']"
[alt]="'img' + i" class="img-thumbnail" [attr.ref]="images[i]['PRODUCT_IMAGE']">
This is how I am trying to bind the image url from the response but I did not get the image.
Can anyone guide me to solve this.
Upvotes: 2
Views: 328
Reputation: 456
they way you are assigning images are wrong.
Try with
this.productImages = this.productDetails[0]['PROD_B'].
and also make a change of below
<div *ngFor="let images of productImages; let i = index" >
<img (mouseenter)="mouseEnter($event)"
[src]="images['PRODUCT_THUMBNAIL']"
[alt]="'img' + i" class="img-thumbnail"
[attr.ref]="images['PRODUCT_IMAGE']">
</div>
Upvotes: 1
Reputation: 12960
I think, you are missing a single quotation over the actual path..(binding the URL as a string but not an expression..) try this:
<img *ngFor="let images of productImages; let i = index" (mouseenter)="mouseEnter($event)" [src]="'images["PRODUCT_THUMBNAIL"]'"
[alt]="'img' + i" class="img-thumbnail" [attr.ref]="'images[i]["PRODUCT_IMAGE"]'">
Upvotes: 0