How do I declare a temporary variable in angular html component?

327 Views Asked by At

I am trying to call a function inside a loop.

How do I call a function and store the return value as temporary variable?

I need to use the return value to display.

Sample below code I want to achieve.

<div *ngFor="let list of sampleLists">
  <div >
    {{ var result = getMyFunction(list) }}

    <div> 
      {{ result.Value}}
      {{ result.Name}}
    </div>
  </div>
</div>
1

There are 1 best solutions below

0
DEV On BEST ANSWER

You can try :

<div *ngFor="let list of sampleLists">
  <div *ngIf="getMyFunction(list) as result">
    <div > 
      {{ result.Value}}
      {{ result.Name}}
    </div>
  </div>
</div>