What are template reference variables?
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
- What are the parts of a component?
- What is data binding? Explain the four types.
- What is the difference between interpolation and property binding?
- How do you pass data from a parent component to a child component?
- How does a child component send data to its parent?
- What is the component lifecycle? Describe the main hooks.