缓存要在Angular 2视图中使用的值?

时间:2018-05-23 06:31:39

标签: angular

我在Angular 2视图中的单个元素中使用了两次long表达式:

<a *ngIf="row.getEmployer()[i]!.getProfileLink()"
   class="x-view-link"
   href="{{ row.getEmployer().getEmployee()[i]!.getProfileLink() }}">
  xv
</a>

我可以以某种方式将row.getEmployer().getEmployee()[i]!.getProfileLink()存储在视图中的变量(称为link,即let link = row.getEmployer().getEmployee()[i]!.getProfileLink())中,然后重用该变量吗?

1 个答案:

答案 0 :(得分:1)

你可以因为你使用条件。

试试:

<a *ngIf="row.getEmployer()[i]!.getProfileLink() as link"

链接现在将包含变量的结果。