ng-container ngif set variable code example
Example 1: set variable inside div angular
myVar = { hello: '' };
<ng-container *ngIf="myVar; let var;">
{{var.hello}}
</ng-container>
myVar$ = of({ hello: '' });
<ng-container *ngIf="myVar$ | async; let var;">
{{var.hello}}
</ng-container>
Example 2: ngTemplate
<div *ngIf='name && lastName; then thereAreParams else thereArentAnyParams'>
</div>
<ng-template #thereAreParams>
<h2>Name is : {{name}} </h2>
<h2>Last name is : {{lastName}} </h2>
</ng-template>
<ng-template #thereArentAnyParams>
<h2>There aren't any parameters</h2>
</ng-template>