2

I have an array which is obtained form a db. I have managed to display the data in the console (I can see the data in chrome console, as shown in Picture) but for some reason no data is displayed in the actual HTML page. Hello and Hello 2 are both printed but no data is printed for {{p.price}} or {{p.propertyId}}

product.component.html

<table class="table" *ngIf='properties && properties.length'> 
    <tbody>
        <tr>Hello</tr>
         <tr *ngFor="let p of properties">
            <td>Hello 2</td>
            <td>{{p.price}}</td>
            <td>{{p.propertyId}}</td>
        </tr>
    </tbody>
</table>

Data in Console

0

1 Answer 1

2

You have array of arrays, so you need nested ngFor, You can use the helper element <ng-container> like

<table class="table" *ngIf='properties && properties.length'> 
    <tbody>
        <tr>Hello</tr>
        <tr *ngFor="let p of properties">
         <ng-container *ngFor="let prop of p">
            <td>Hello 2</td>
            <td>{{prop.price}}</td>
            <td>{{prop.propertyId}}</td>
        </ng-container>
        </tr>
         </span>
    </tbody>
</table>
Sign up to request clarification or add additional context in comments.

5 Comments

Unfortunately, this HTML is invalid. The only allowed direct child elements of a tr are td or th.
@connexo should be fine now, you can use ng-container
I haven't downvoted. And no, span is illegal there and creates invalid HTML.
anyways should be fine now
@Sajeetharan Thanks for the Help :) !

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.