dangerChihuahua007
dangerChihuahua007

Reputation: 20875

Caching a value to be used within an Angular 2 view?

I use a long expression twice within a single element in an Angular 2 view:

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

Could I somehow store row.getEmployer().getEmployee()[i]!.getProfileLink() inside a variable (called say link, ie let link = row.getEmployer().getEmployee()[i]!.getProfileLink()) within the view and then reuse that variable?

Upvotes: 0

Views: 23

Answers (1)

user4676340
user4676340

Reputation:

You can because you use a condition.

Try that :

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

Link will now contain the result of your variable.

Upvotes: 1

Related Questions