Bird
0
0

What is wrong with this Angular template snippet?

medium📝 Debug Q14 of 15
Angular - Templates and Data Binding
What is wrong with this Angular template snippet?
<input [value]=username>
AThe variable username must be a string literal.
BSquare brackets cannot be used on input elements.
CThe property name should be in parentheses, not brackets.
DThe value should be in quotes: [value]="username".
Step-by-Step Solution
Solution:
  1. Step 1: Check property binding syntax

    Property binding requires the value inside quotes to be a valid expression.
  2. Step 2: Identify missing quotes

    Here, username is not quoted, so Angular treats it as invalid syntax.
  3. Final Answer:

    The value should be in quotes: [value]="username". -> Option D
  4. Quick Check:

    Property binding expression must be quoted [OK]
Quick Trick: Always quote expressions inside square brackets [OK]
Common Mistakes:
  • Omitting quotes around binding expressions
  • Using parentheses instead of brackets for property binding
  • Thinking brackets can't be used on input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes