javascript - Angular: How to show icon.png depending on the attribute of a item? -


i have array of objects looks this:

[{"name":"steve", "hourly_wage":16, "status":"part-time"}, {"name":"maria", "hourly_wage":25, "status":"full-time"}, {"name":"jose", "hourly_wage":21, "status":"former"}] 

i want display icon each person's employment status. full circle full time, half circle part time , empty circle former. how can go doing in javascript/angular? i'm thinking if statement of sort inside ng-hide?

most generic way in opinion create mapping, use it.

js:

$scope.statusiconmapping = {"part-time": "half_circle.jpg",      "full-time": "full_circle.jpg",      "former": "empty_circle.jpg" }; 

markup:

<div ng-repeat="employee in employees">     ...     <img src="{{statusiconmapping[employee.status]}}" /> </div> 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -