【问题标题】:Unable to show different div if data is empty如果数据为空,则无法显示不同的 div
【发布时间】:2018-03-30 08:47:46
【问题描述】:

我是 angular 2 的初学者,如果列表为空,我无法理解如何显示不同的 div。我已经编写了 ngIf 来检查数据是否存在。在线搜索,所有结果都要求我检查长度或使用!符号,但它不起作用。下面是我的项目的 github,下面是我想显示列表空状态的 json 结果。

Git

Json 输出

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

我希望在列表组件中显示一条名为 no data 的消息

【问题讨论】:

  • 你能用 *ngIf 发布你的代码吗,会更容易回答!
  • iproducts: IEmail[];是错误的,我认为,因为你不是存储数组 init 而是 json

标签: angular angular2-forms angular2-directives


【解决方案1】:

由于您的 json 返回 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-20
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    • 2015-02-19
    相关资源
    最近更新 更多