I have a question about declaring temporary variables in Angular template to use it for multiple element (childs) like: (Idea / Expected)
<ng-container *ngVar="let theValue = item.getValue()">
<div>{{ theValue }}</div>
<div [class.foo]="theValue == 42">foo</div>
</ng-container>
I already have a workaround for this. Just wrap the value in a array and use ngFor like: (Workaround)
<ng-container *ngFor="let theValue of [item.getValue()]">
<div>{{ theValue }}</div>
<div [class.foo]="theValue == 42">foo</div>
</ng-container>
But this is a bit dirty. - Is there an official solution?
My idea is to reduce the computing of the value over and over again for the same value. I just want to reuse the computed value for multiple childs and / or attributes.
I do not want to compute getValue()
every time. Because I get the same value anyway. To hold the value temporary in a group element it can improve the performance and readability.
It should be possible without a custom directive. I mean to have seen something like this before.