Recall & Review
beginner
What is a template reference variable in Angular?
A template reference variable is a way to access a DOM element or Angular component directly within the template using a special syntax with the # symbol.
Click to reveal answer
beginner
How do you declare a template reference variable for an input element?
You declare it by adding #variableName inside the input tag, for example: <input #myInput>. This lets you access the input element directly in the template.
Click to reveal answer
intermediate
How can you use a template reference variable to get the value of an input field in Angular?
You can use the variable inside the template, for example: <button (click)="doSomething(myInput.value)">. This passes the current value of the input to the component method.
Click to reveal answer
intermediate
Can template reference variables access Angular components as well as DOM elements?
Yes, if you assign a template reference variable to a component selector, you can access the component instance and call its methods or access its properties directly in the template.
Click to reveal answer
beginner
What is the scope of a template reference variable in Angular templates?
The scope of a template reference variable is limited to the template where it is declared. It cannot be accessed in other templates or component classes directly.
Click to reveal answer
How do you declare a template reference variable named 'inputBox' on an input element?
✗ Incorrect
Template reference variables are declared using the # symbol followed by the variable name inside the element tag.
What can a template reference variable NOT directly access?
✗ Incorrect
Template reference variables cannot directly access component class properties; they access elements or component instances in the template.
Which of these is a valid use of a template reference variable in a button click event?
✗ Incorrect
You use the variable name directly without # inside event bindings.
If you declare , what does compRef represent?
✗ Incorrect
When used on a component selector, the template reference variable points to the component instance.
Where can you use a template reference variable declared in a template?
✗ Incorrect
Template reference variables are only accessible within the template where they are declared.
Explain how to create and use a template reference variable to get the value of an input field in Angular.
Think about how you can grab the input's current text without using component code.
You got /3 concepts.
Describe the difference between accessing a DOM element and an Angular component using template reference variables.
Consider what you get when you put #var on a normal HTML tag vs a component tag.
You got /3 concepts.