我有一个从数据库获取的数组。我已经设法在控制台中显示数据(我可以在chrome控制台中看到数据,如图所示),但由于某种原因,实际的HTML页面中没有显示数据。 Hello 和 Hello 2 均已打印,但未打印 {{p.price}} 或 {{p.propertyId}}
的数据产品.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>
最佳答案
您有数组的数组,因此您需要嵌套 ngFor
,您可以使用辅助元素 <ng-container>
喜欢
<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>
关于javascript - 无法访问数组 Angular 的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48041522/