首页 > 解决方案 > 向 Angular 表达式中的三元运算符添加徽标

问题描述

我想根据状态是否处于活动状态向我的 HTML 添加两个不同的徽标。

现在我有这个,它有效:

<td>{{customer.activeStatus?"yes":"no"}}</td>

但我想有一些类似的东西:

<td>{{customer.activeStatus? "<i class='fas fa-lightbul'></i>":"no"}}</td>

如果是真的,我想从 FontAwesome 获得这个标志,如果是假的,那么“不”。

标签: angularternary-operator

解决方案


你可以试试*ngIf and else

<td>
  <i *ngIf="customer.activeStatus;else elsePart" class='fas fa-lightbul'></i>
  <ng-template #elsePart>No</ng-template>
</td>

有关更多详细信息,请查看此链接


推荐阅读