用于空字符串验证的 Ngif 角度 5

Aid*_*ard 2 typescript angular-ng-if angular angular5

我正在努力验证从服务器检索到的空字符串

它通常很简单,只是不起作用

<div class="ui-g-2 info-txt"
     *ngIf="appointment.Notes !==null || 
     appointment.Notes !== ''">
     <i class="fa fa-commenting-o" aria-hidden="true"</i>
</div>

<div class="ui-g-5 info-txt"
     *ngIf="appointment.Notes !==null ||     
     appointment.Notes !== ''">
     *emphasized text*{{appointment.Notes}}
</div>

<div class="ui-g-7 info-txt"
     *ngIf="appointment.Notes === null || 
     appointment.Notes === ''"
     style="padding-top: 0;">
     no hay notas disponibles
</div>
Run Code Online (Sandbox Code Playgroud)

所以我正在检查一个空值或没有任何内容的字符串,问题是它仍然显示图标和空字符串

当 no hay 里面有一条消息时......没有显示,所以它在那一边工作得很好

任何帮助都非常感谢多年来一直坚持这一点。

我确定这是一个明显的我只是看不到它

nir*_*aft 6

您可以使用双重否定来检查值是否不是 undefined/null 或 Empty。前任:*ngIf="!!name".

这将防止显示所有 Null、未定义或空值。