Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a template reference variable named 'inputRef'.
Angular
<input type="text" [1]>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' or '@' instead of '#' to declare the reference variable.
Forgetting the '#' symbol.
✗ Incorrect
In Angular templates, a template reference variable is declared using the '#' symbol followed by the variable name.
2fill in blank
mediumComplete the code to bind the input's value to a paragraph using the template reference variable 'inputRef'.
Angular
<input type="text" #inputRef> <p>{{ [1].value }}</p>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than the declared template reference.
Trying to access the value without the '.value' property.
✗ Incorrect
The template reference variable 'inputRef' can be used directly in interpolation to access the input's properties like 'value'.
3fill in blank
hardFix the error in the button click event to log the input's value using the template reference variable 'myInput'.
Angular
<input type="text" #myInput> <button (click)="logValue([1])">Log</button>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the whole input element instead of its value.
Using a method 'getValue()' which does not exist.
✗ Incorrect
To get the input's current value, use 'myInput.value' inside the event binding.
4fill in blank
hardFill both blanks to create a template reference variable 'box' and use it to set the paragraph text.
Angular
<input type="text" [1]> <p>{{ [2].value }}</p>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '#' inside interpolation.
Using different names for declaration and usage.
✗ Incorrect
Declare the template reference variable with '#box' and use 'box' inside interpolation to access its value.
5fill in blank
hardFill all three blanks to declare a template reference 'userInput', bind its value to a span, and use it in a button click event.
Angular
<input type="text" [1]> <span>{{ [2].value }}</span> <button (click)="submit([3].value)">Submit</button>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names between declaration and usage.
Using '#' inside interpolation or event binding.
✗ Incorrect
Declare the template reference with '#userInput', use 'userInput' inside interpolation and event binding to access the input's value.