Search code examples
javascriptangularangular13

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?


Solution

  • 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>