[英]Angular *ngIf="data$ async as data && data.payload; else noContent"
I want to conditionally show a block only if it contains data, otherwise I will show a noContent block.我只想有条件地显示一个块,如果它包含数据,否则我将显示一个 noContent 块。 the data is fetched from the server.
数据是从服务器获取的。
<ng-container *ngIf="data$ async as data && data.payload; else noContent">
{{data.payload | json}}
</ng-container>
<ng-template #noContent> No content found </ng-template>
notes: 1- I dont want to implement two s, ie:注意: 1- 我不想实现两个 s,即:
<ng-container *ngIf="data$ async as data ; else noContent">
<ng-container *ngIf="data.payload; else noContent">
{{data.payload | json }}
</ng-container>
</ng-container>
...
2- the following statements are working 2-以下语句有效
*ngIf="xx && yy"
*ngIf="data$ as data"
*ngIf="xx && data$ as data"
*ngIf="(data$ as data)?.payload?.length>0; else noContent"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.