0

I have data retrieved from the API in the following form

[
    {
        "end_date": 1640908800000,
        "rev": 151,
        "usage_limit": 0,
        "reason_deleted": null,
        "picture_detail": "test",
        "revtype": 0,
        "linked_type": "SPECIFIC",
        "modified_date": 1644893309181,
        "type": "OPEN",
        "created_by": "[email protected]",
        "is_multiple": null,
        "campaign_name": "Blewah 2022",
        "is_deleted": false,
        "is_auto_apply": true,
        "modified_by": "[email protected]",
        "campaign_code": "BLEWAH2",
        "id": 76,
        "created_date": 1644893309181,
        "picture_banner": "test",
        "remarks": "Lorem ipsum dolor sit amet.",
        "start_date": 1609459200000,
        "status": "APPROVED"
    },
    {
        "end_date": 1644969600000,
        "rev": 152,
        "usage_limit": 0,
        "reason_deleted": null,
        "picture_detail": "",
        "revtype": 0,
        "linked_type": "SPECIFIC",
        "modified_date": 1644900601884,
        "type": "OPEN",
        "created_by": "[email protected]",
        "is_multiple": null,
        "campaign_name": "BLEWAH 4",
        "is_deleted": false,
        "is_auto_apply": false,
        "modified_by": "[email protected]",
        "campaign_code": "BLEWAH",
        "id": 78,
        "created_date": 1644900601884,
        "picture_banner": "",
        "remarks": "",
        "start_date": 1644883200000,
        "status": "APPROVED"
    },
    {
        "end_date": 1644969600000,
        "rev": 153,
        "usage_limit": 0,
        "reason_deleted": null,
        "picture_detail": "",
        "revtype": 1,
        "linked_type": "SPECIFIC",
        "modified_date": 1644900601884,
        "type": "OPEN",
        "created_by": "[email protected]",
        "is_multiple": null,
        "campaign_name": "BLEWAH 4",
        "is_deleted": false,
        "is_auto_apply": false,
        "modified_by": "[email protected]",
        "campaign_code": "BLEWAH",
        "id": 78,
        "created_date": 1644900601884,
        "picture_banner": "",
        "remarks": "",
        "start_date": 1644883200000,
        "status": "APPROVED"
    },
]

Now I need to get the data inside that array, and display it on table on Angular 11 using Typescript, either it's the key, like "start_date", and the value of the key, like "status": "APPROVED". I already try to use Object.value and Object.key, but the return is like this

The result of my work for now

I got the key, but the value just like [Object]. I need to get the value and display it on table using Angular Material Table. Can someone help me please? Thank you.

2
  • Please post your relevant ts and html code. Commented Feb 20, 2022 at 7:30
  • Try using ngFor. If you want to use Object.key add html code in your question. Commented Feb 20, 2022 at 7:31

2 Answers 2

1

If building a table display, you can also make an array of headers, push keys from the first element and in template display the headers and loop through items in your json and display them. Like: https://stackblitz.com/edit/angular-key-value-table-qnctbf

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. You saved me 😄
0

Use the keyvalue pipe.

<tr *ngFor="let item of items">
  <ng-container *ngFor="let prop of item | keyvalue">
    <td> prop.key </td>
    <td> prop.value </td>
  </ng-container>
</tr>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.