site
site

Reputation: 247

How to display data inside object inside json/json using angular

I get this JSON.

[
    {
        "id": 11,
        "parent_category": null,
        "name": "name11"
    },
    {
        "id": 12,
        "parent_category": {
            "id": 11,
            "name": "name11",
            "parent_category": null
        },
        "name": "name12"
    },
    {
        "id": 13,
        "parent_category": {
            "id": 11,
            "name": "name11",
            "parent_category": null
        },
        "name": "name13"
    }  
]

I want to show in view parent_category.name where parent_category is not null.

  <mat-select formControlName="parent_category">
                      <mat-option>--</mat-option>
                      <mat-option *ngFor="let p_g of mydata" [value]="p_g.id">
                        {{p_g.name}}
                      </mat-option>
                    </mat-select>

Please, Can you share with me any idea how to show it ?

Upvotes: 0

Views: 43

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222720

You need to access internal object parent_category

<mat-option *ngFor="let p_g of mydata" [value]="p_g.id">
      {{p_g.parent_category?.name}}
 </mat-option>

Upvotes: 1

Related Questions