gpt4 book ai didi

javascript - 无法访问数组 Angular 的数据

转载 作者:行者123 更新时间:2023-11-29 20:58:21 25 4
gpt4 key购买 nike

我有一个从数据库中获取的数组。我已经设法在控制台中显示数据(我可以在 chrome 控制台中看到数据,如图所示)但由于某种原因没有数据显示在实际的 HTML 页面中。 HelloHello 2 都被打印出来了,但是没有为 {{p.price}} 或 {{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

最佳答案

你有数组的数组,所以你需要嵌套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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com