What are template reference variables?

Angular components and templates · Freshers and experienced

Model answer

A template reference variable, written with a hash such as #nameInput on an element, gives you a handle to that element or component inside the same template. You can then read its value or call its methods: <input #nameInput> <button (click)="save(nameInput.value)">.

For a component or directive, the variable gives access to the instance. They are handy for small interactions and avoid extra class properties.

Learn this topic

Angular Tutorial: Beginner to Advanced .

Sign in to add your own answer.

More questions