Angular Discussion Forums

There's no such thing as a stupid question. Ask. Discuss. Learn.

Best way to dynamically change src

I have a *ngFor loop that gives me a list of items and i display that list. I need to add an image that matches the list item so i have to dynanically change the url for each item. Whats the best way to do this?

div *ngFor="let item of items; let i = index' [attr.index]= 'i'>
img class="index" src="img/index.png">
div>

So basically i want the class name to be the index value and append the index value to the scr string

class='0' src='img/0.png
class='1' src='img/1.png
class='2' src='img/2.png

Peter Puck 2 months ago
  • Whitelisted Links