想要隱藏列表,如果它從json中檢索未定義的。任何人都可以幫忙嗎?如果變量值在角度4中未定義,如何隱藏列表?
HTML file:
<ul>
<li *ngFor="let item of items | async"><span *ngIf="item?.name">{{item.name}}</span></li>
</ul>
JSON文件:
{
"chat" : {
"-Kss3KDwaLDpzAHUKtJN" : {
"id" : "11",
"name" : "Shanth",
"message" : "Hi ..!"
},
"-Kss3Kc9c2Ie5IXypqNe" : {
"id" : "12",
"name" : "",
"message" : "Hi .."
},
"-KssBwcJhkNCsxUUhsXb" : {
"id" : "13",
"name" : "Prasanth",
"message" : "Hi .."
}
}
我越來越像結果如下:
1. Shanth
2.
3. Prasanth
我不想顯示第二個列表。它應顯示爲
1. Shanth
2. Prasanth
引發錯誤「無法找到類型爲'object'的不同支持對象'[object Object]'。NgFor僅支持綁定到Iterables,比如」數組「 –
對不起,我認爲我可以寫得很快。在ng容器中使用'* ngFor =「let item | async」' – trichetriche
我剛剛編輯了我的答案,以便您可以看到它 – trichetriche