angular - 在 ngFor 中测试 null
问题描述
我想在不为空payment.invoice.reference
时显示。invoice
我试过这个:
<tr *ngFor="let payment of payments; index as i">
<td>
<span *ngIf="payment.invoice">{{payment.invoice.reference}}</span>
<span *ngIf="!payment.invoice">Notinh</span>
</td>
</tr>
我试过这个:
<tr *ngFor="let payment of payments; index as i">
<td>{{payment?.invoice.reference}}</td>
</tr>
但那是行不通的。
任何的想法 ?
解决方案
你已经在付款了吗?,它与您需要在发票后添加的内容相同。它被称为安全导航算子,
<td>{{payment?.invoice?.reference}}</td>
或者,您也可以使用*ngIf
指令
推荐阅读
- java - CodenameOne - 内部类导致 dex 构建错误
- javascript - 在javascript中将变量的值解析为另一个变量
- swift - Swift UI @ObservedObject 不起作用,在实现另一个协议时发现奇怪的行为
- java - Java 11:如何总结两个 Single
> 在java中? - python - Pandas 在多列上应用逐行函数
- string - 我正在尝试通过使用 malloc 分配内存来创建一个包含 n 个字符的字符串,但我遇到了问题
- reactjs - 如何从 React.js 中的数组渲染 {columns.render}?
- notifications - 如何使通知下拉而不只显示在状态栏上?
- r - 安装软件包时 .dll 文件的权限被拒绝
- microsoft-graph-api - 使用 Microsoft Graph API 发送投票选项