javascript / beginner
Snippet
Template Reference Variables
A template reference variable (declared with #) creates a reference to a DOM element, making it accessible anywhere in the template without needing component logic.
snippet.js
1
2
<input #userEmail placeholder="Enter email"><button (click)="save(userEmail.value)">Save</button>
angular
Breakdown
1
#userEmail
Declares a local template variable named 'userEmail' that points to the input element.
2
userEmail.value
Accesses the current 'value' property of the referenced input element.