R
R
reactreact2016-01-20 10:28:30
JavaScript
reactreact, 2016-01-20 10:28:30

How to write such a condition correctly (angular2)?

There is data:

this.users = [{
name: 'username',
category: 'category'
}]

It is necessary to insert a certain image into the html code on the page, depending on the category of the user.
<div class="user" *ngFor="#user of users"><img src="img/icon.png" alt="">{{user.name}}</div>

The icon.png image needs to be replaced. Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2016-01-20
@reactreact

I recommend adding the path to the icon at the data source level, or in the controller. This case can then be easily covered by tests, without the need to instantiate the UI element.

L
lega, 2016-01-20
@lega

try[src]="user.category + '.png'"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question