【发布时间】:2018-07-25 22:22:21
【问题描述】:
我正在循环使用 *ngFor 的 json 文件。在遍历数据时,我想检查每个人,如果它没有颜色数组。我用 *ngIf 来做这件事。
JSON
[
{
"name": "Peter",
"colors": [
{
"color": "blue"
},
{
"color": "yellow"
}
]
},
{
"name": "Maria"
}
// has no colors array
]
HTML
<div *ngFor="let person of persons">
<div *ngIf=" what comes here?? ">
<p>{{person.name}} has no colors</p>
</div>
</div>
如果一个人没有颜色数组,我该如何检查?
【问题讨论】:
标签: arrays json angular ngfor angular-ng-if