Bird
0
0

What will happen if you use <a routerLink="['/home']">Home</a> without square brackets around routerLink?

medium📝 component behavior Q5 of 15
Angular - Routing
What will happen if you use <a routerLink="['/home']">Home</a> without square brackets around routerLink?
AAngular treats it as a string literal and navigates to '/home'.
BAngular navigates to the root path '/' instead.
CAngular throws a template parse error.
DAngular ignores the routerLink and does nothing on click.
Step-by-Step Solution
Solution:
  1. Step 1: Understand binding syntax

    Using square brackets is required for property binding; without them, Angular treats it as a plain attribute.
  2. Step 2: Analyze the invalid syntax

    Since the value is an array syntax string but not bound, Angular throws a parse error.
  3. Final Answer:

    Angular throws a template parse error. -> Option C
  4. Quick Check:

    Missing brackets with array syntax = parse error [OK]
Quick Trick: Use brackets for binding arrays in RouterLink [OK]
Common Mistakes:
MISTAKES
  • Omitting brackets for array binding
  • Assuming string works without brackets
  • Ignoring Angular template errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes