forum subscription

Wanna help programmers by answering latest Angular questions?

We will email you whenever a new question is posted in Angular section. Max 2 emails per week.

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 1 week ago
  • Whitelisted Links