Reputation: 5167
This is source code
<div>
{{ getActualData() }}
</div>
<div>
{{ getVirtualData() }}
</div>
<div>
{{ getActualData() - getVirtualData() }}
</div>
This is what I want.
<div>
{{ actual = getActualData() }}
</div>
<div>
{{ virtual = getVirtualData() }}
</div>
<div>
{{ actual - virtual }}
</div>
Because two functions are complex, I would like to save data temporarily and calculate difference shortly. Is there any way to do this?
Upvotes: 13
Views: 22053
Reputation: 222582
You can declare variable in template using let
that will evaluate the function and get the result , using ngIf to actually check if the value is there and assign to the variable
<div *ngIf="getActualData(); let actual" >
<div *ngIf="getVirtualData(); let virtual" >
{{actual - virtual}}
</div>
Upvotes: 26
Reputation: 2487
you can try :
<div *ngIf="getActualData(); let actual">
<div *ngIf="getVirtualData(); let virtual">
{{ actual - virtual }}
</div>
</div>
</div>
this is a workaround but should work
Upvotes: 6