Bird
0
0

What is wrong with this Angular code for passing data from parent to child?

medium📝 Debug Q14 of 15
Angular - Component Interaction
What is wrong with this Angular code for passing data from parent to child?
Parent template:
<child-comp data="parentData"></child-comp>

Child component TS:
@Input() data: string;
AThe parent should use parentheses: <code>(data)="parentData"</code>.
BThe child should use @Output() instead of @Input().
CThe parent should use square brackets: <code>[data]="parentData"</code>.
DThe child should declare data as a function, not a property.
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct binding syntax

    Passing data from parent to child requires property binding with square brackets.
  2. Step 2: Analyze given code

    Using data="parentData" passes a string literal, not the variable value.
  3. Final Answer:

    The parent should use square brackets: [data]="parentData". -> Option C
  4. Quick Check:

    Property binding needs [] around attribute [OK]
Quick Trick: Use [] for passing variables, not quotes [OK]
Common Mistakes:
  • Using string literals instead of variable binding
  • Confusing @Input and @Output decorators
  • Using event binding () for data input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes