I am trying to declare a variable of my own within *ngFor
but it throws error and is not working.
I loop through a collection of buttons
, and show icon whenever the condition inside *ngIf
is satisfied.
<button *ngFor="let button of buttons;" type="button">
<i *ngIf="button.icon || (button.conditional && button.iconConditional)" [attr.class]="button.icon"></i>
</button>
I want to reuse the condition within *ngIf
to add a class conditionally to <button>
as well.
When I try to do as below, it fails at "let showIcon
".
<button *ngFor="let button of buttons; let showIcon = button.icon || (button.conditional && button.iconConditional)" type="button" [ngClass]="{'icon':showIcon}">
<i *ngIf="showIcon" [attr.class]="button.icon"></i>
</button>
Can someone please help.
Even trying to add showIcon variable within ngFor throws me error as below: