Skip to content
Advertisement

let variable in angular ngif with multiple conditions

In Angular (13) is there a way to assign the result of a function to a variable (in the .html part of a component, not template) having multiple conditions in ngIf

<div *ngIf="let getMyVar() as myVar && isVisible && isClean">
    {{ 'this is myVar: ' + myVar }}
</div>

if not what workaround is possible to implement?

Advertisement

Answer

did not find anything better than splitting the ngIf in two

<ng-container *ngIf="getMyVar(); let myVar">
    <div *ngIf="isVisible && isClean">
        {{ 'this is myVar: ' + myVar }}
    </div>
</ng-container>
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement