S
S
Saharman2018-11-09 21:47:14
Angular
Saharman, 2018-11-09 21:47:14

How do I convert the received json into an array that I could run through ngFor?

I get this Json from the server:

{
    "code": 0,
    "error": null,
    "data": [
        {
            "id": 2,
            "name": "A"
            "Numbers": []
        },
        {
            "id": 3,
            "name": "B,
            "description": "V",
            "Numbers": []
        }
    ]
}

I tried to convert it with:
result.json().data
but it gives an error that json is not a function. I also used JSON.parse, but it didn't work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Demian Smith, 2018-11-09
@Saharman

No need for result.json()
The data is already there.
result.data is sufficient.
(assuming you are using Angular > 4.3)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question