【发布时间】:2018-07-02 07:15:04
【问题描述】:
我想遍历我的 json 文件中的对象数组。
json
[
{
"name": "Mike",
"colors": [
{"name": "blue"},
{"name": "white"}
]
},
{
"name": "Phoebe",
"colors": [
{"name": "red"},
{"name": "yellow"}
]
}
]
html
<div *ngFor="let person of persons">
<p>{{person.name}}</p> <!-- this works fine-->
<p *ngFor="let color of person.colors"> <!--I want to list the colors of the person here-->
{{color.name}}
</p>
</div>
我无法访问一个人的颜色数组。我该如何实现?
我已经看过这些帖子,但他们的解决方案对我没有帮助:
【问题讨论】:
-
让 person.colors 的颜色。投票结束错字。
-
@JBNizet 抱歉,我在这里的帖子中忘记了这一点,但我的代码中有它,所以这不是问题
-
不,打开控制台会立即产生错误和解决方案@Pac0
-
关闭第一段。检查您的控制台是否有错误消息。