0

I'm trying to store data from api to string array in angular5 and use each of the strings as img src but i don't think i'm getting it right. I'm currently doing it this way:

component.ts

let allOther_images: string[] = [];
 data.other_images.forEach(item => {
 allOther_images.push(item.image);
 console.log(allOther_images);
 ["http://web.apiendpoint.com/media/products/dhjsh_HA3PAf1.png"] //console output
})

component.html

<div class="other-images" style="padding: 20px">
 <div class="item" *ngFor="let item of allOther_images">
  <img [src]="item" alt="" style="height: 250px;">
  <span class="remove-img">&times;</span>
 </div>
</div>

With this even the image element does not show in console so I'm guessing I have the *ngFor quite wrong. Can you spot where I have gone wrong?

1
  • could you provide more details about your code? I think you should remove the let keyword. Commented May 13, 2018 at 13:21

1 Answer 1

1

Declare allOther_images globally,

allOther_images: string[] = [];

and assign the values within your response,

data.other_images.forEach(item => {
 allOther_images.push(item.image);
})

STACKBLITZ DEMO

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.