gpt4 book ai didi

javascript - 尝试在 Angular 客户端显示数据

转载 作者:行者123 更新时间:2023-11-28 17:22:20 24 4
gpt4 key购买 nike

当我尝试获取街道名称时,我得到了[object Object],在客户端显示JSON数据的最佳方式是什么。

我能够显示街道名称,但无法显示其他部分。如何检索其他元素?

//Interface 

export interface Street {
name: string;
color: string;
}

export interface Place {
name: string;
streets: Street[];
stopLights: string[];
similarStreets: string[];
}

// Client Side
<h2>Place List</h2>
<ul *ngFor="let place of places.places">
<li>{{place.name}}</li> //This works and shows the name
<li>{{place.color}}</li> //showing [object Object] for color

</ul>

//JSON Data
{
"places": [
{
"name": "San Jose",
"street": [
{
"name": "1st Street",
"color": "Sharkish"
},
{
"name": "Santa Clara",
"color": "49ers"
}
],
}

最佳答案

使用另一个*ngFor作为颜色

<h2>Place List</h2>
<ul *ngFor="let place of places.places">
<li>{{place.name}}</li>
<li *ngFor="let street of place.street">{{street.color}}</li>
</ul>

关于javascript - 尝试在 Angular 客户端显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52219048/

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