Angular · Junior · Question 15 of 75

What is a template reference variable #nameInput?

<input #nameInput />
<button (click)="greet(nameInput.value)">Greet</button>

Explanation

#ref on a DOM element points to that element; on a component it points to the component instance. The variable is available in the template only; in the class you use viewChild() to get a reference.

Further reading

Problem with a question

Angular · Junior · question 15

Test yourself

Take the Angular · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz