如果数据为空,则无法显示不同的div
问题描述:
我是角度2的初学者,无法理解如果列表为空时如何显示不同的div。我写入了ngIf来检查数据是否存在.Searched online and all结果要求我检查长度或使用!符号,但它不起作用。下面是我项目的github,下面是我想要显示列表空状态的json结果。如果数据为空,则无法显示不同的div
JSON输出
我期待显示一个消息调用列表组件
答
没有数据由于您的JSON返回空值,而不是一个空字符串,你应该能够对数据点进行检查
<!-- list.component.html -->
<tbody>
<tr *ngFor='let lst of iproducts.Registers'>
...
</tr>
<tr *ngIf='!iproducts.Registers'>
<td colspan="3">No List Data Found</td>
</tr>
</tbody>
你可以用* ngIf发布你的代码,会更容易回答! – JayDeeEss
iproducts:IEmail [];是错的,我认为,因为你没有存储数组init或json –