如果数据为空,则无法显示不同的 div

Unable to show different div if data is empty

我是 angular 2 的初学者,无法理解如何显示不同的 div 如果列表 empty.I 已经写入并且 ngIf 来检查数据是否 exists.Searched 在线和所有结果要求我检查长度或使用!符号,但它不是 work.Below 是我的项目的 github,下面是 json 结果,我也想显示列表为空的情况。

Git

Json输出

{"status_message":"Success","status_code":"0","Registers":null}

我期望在列表组件中显示一条名为无数据的消息

因为你的 json returns 是一个 null 而不是空字符串,你应该能够只对该数据点进行 ngIf 检查

<!-- 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>