NgIf if 属性 不是未定义?

NgIf if property is not undefined?

有结构指令ngIf:

<tr *ngIf="p.taxbalance">
</tr>

问题是对象 p 中没有 属性 taxbalance

ERROR TypeError: Cannot read property 'taxbalance' of undefined

我尝试使用这个签名:

<tr *ngIf="p?.taxbalance"></tr>

但是也不行

试试 $any() 类型转换函数

您可以使用 $any() 转换函数将表达式转换为任意类型

<tr *ngIf="$any(p).taxbalance"></tr>