0

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 ?

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

This will render an "empty" option, which probably is not what OP wants.

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.