0

I am using Angular 9.

I am trying to construct a dynamic table from a 2 dimensional array.

I have the following which displays the first element succesffully.

<mat-card class="approval-edit-card-nominated">
    Nominated Evaluators
    <div>
        {{nominationAllOf[0].nominations[0].evaluatorInfo.personalInfo.name.firstName}}
        {{nominationAllOf[0].nominations[0].evaluatorInfo.personalInfo.name.lastName}}
    </div>
</mat-card>

However, I want to make a table that displays all rows and columns. So I try the following:

<mat-card class="approval-edit-card-nominated">
    Nominated Evaluators {{nominationAllOf[0].nominations.length}}
    <div>
        <table>    
            <tr *ngFor="let nomination of nominationAllOf">
                <td *ngFor="let item of nomination">
                    {{item.evaluatorInfo.personalInfo.name.firstName}}
                    {{item.evaluatorInfo.personalInfo.name.lastName}}
                </td>
            </tr>
        </table>
    </div>
</mat-card>

The {{nominationAllOf[0].nominations.length}} is 3. But the table is just not displayed.

Question

How do I display the table from the 2 dimensional array?

Error

ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.

Thanks

1
  • <td *ngFor="let item of nomination.nominations"> Commented Jul 6, 2020 at 6:24

1 Answer 1

2

You are missing a .nominations in your inner loop:

<table>    
    <tr *ngFor="let nomination of nominationAllOf">
        <td *ngFor="let item of nomination.nominations">
            {{item.evaluatorInfo.personalInfo.name.firstName}}
            {{item.evaluatorInfo.personalInfo.name.lastName}}
        </td>
    </tr>
</table>

Tip: you can easily debug such cases by using json pipe. In this case, you could use:

<tr *ngFor="let nomination of nominationAllOf">
{{ nomination | json }}

and you would see the contents of the nomination object.

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

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.