Template reference variables code example
Example 1: set variable inside div angular
// Synchronous:
myVar = { hello: '' };
<ng-container *ngIf="myVar; let var;">
{{var.hello}}
</ng-container>
// Using async pipe:
myVar$ = of({ hello: '' });
<ng-container *ngIf="myVar$ | async; let var;">
{{var.hello}}
</ng-container>
Example 2: template reference variable
<input type="text" #firstNameInput><input type="text" #lastNameInput>
Example 3: template reference variable
show(lastName: HTMLInputElement){ console.log(lastName.value);}