Lets say I have a service that returns a list ob objects.
[
{item: 'box', price: 10, state: 'N'},
{item: 'toy', price: 15, state: 'U'},
{item: 'ink', price: 20: state: 'O'}
]
In the webapp I like to map the state to readable text. I would put a map in my component and use it in the template.
Component
map = new Map ([
[ "N", "new in stock" ],
[ "U", "used but ok" ],
[ "O", "out of stock" ]
]);
Template
<tr *ngFor="let d of data">
<td>{{ d.item }}</td>
<td>{{ map.get (d.state) }}</td>
</tr>
I am not sure thats the best strategy to do that. It is simple and easy but I would favor a way that is more related to the template (the view) instead of the component (the control).
I can think of a pipe that translates but maybe thats a overkill for that simple problem.
Thanks for suggestions and comments.