0

I have a configuration like the following in the component file :

  public status: any = {
    PRG: "In Progress",
    COMP: "Completed",
    FAIL: "Failed",
  };

Now in the template file I have a loop and in there, the status is coming as one of the field. I am trying to access value from status like the following:

<tr *ngFor="let item of items">
    <td>{{ config[item.status] }}</td>
</tr>

But I am not getting any value here. How to access the value from JSON object ?

UPDATE: My items looks like the following:

[
   {
      "id":3,
      "description":"Description",
      "status":"COMP",
      "user_id":"user2"
   },
   {
      "id":4,
      "description":"Description",
      "status":"INPRG",
      "user_id":"user2"
   }
]

and the HTML looks like the following :

<div class="d-flex arm-release_status badge{{configurations[item.status]}}">
      <p>{{status[item.status]}}</p>
</div>
Alexis
  • 1,685
  • 1
  • 12
  • 30
Happy Coder
  • 4,255
  • 13
  • 75
  • 152

1 Answers1

0

You are using a config property that doesn't seem to exist, use status instead.

<tr *ngFor="let item of items">
  <td>{{ status[item.status] }}</td>
</tr>

PS: To also add a class use something like

<div [ngClass]='"badge-"+status[item.status].toLowerCase()'>
      <p>{{status[item.status]}}</p>
</div>
Rob Monhemius
  • 4,822
  • 2
  • 17
  • 49