Home > Enterprise >  Angular tree from JSON response
Angular tree from JSON response

Time:09-14

I have a response like:

[
    {
        "id": 1,
        "title": "ab",
        "description": "gazeta",
        "published": true,
        "comments": [
            {
                "id": 1,
                "content": null
            },
            {
                "id": 3,
                "content": null
            },
            {
                "id": 4,
                "content": null
            }
        ]
    }            
]

How can I make tree in Angular? Any examples of impelementation, or documentation, or working example.

CodePudding user response:

https://github.com/hivivo/ngx-json-viewer

There is a json viewer.

Please ask your questions a bit more specific. A google search took me 1 second angular folding json

Is there a way to display valid json in a collapsable format in Angular 2?

CodePudding user response:

create an interface:

export interface yourInterface{
    id: number;
    title: string;
    description: string;
    published: boolean;
    comments: {id: number; content: string;}[]

}

and declare your http request like this:

this.httpService.get<yourInterface[]>('url...')

CodePudding user response:

I hade same problem and i used Angular Material-Tree

https://material.angular.io/components/tree/examples

Hope this helps!

  • Related