What is the purpose of the @Input decorator in Angular?
The @Input decorator allows a parent component to pass data to its child component. It marks a property in the child component as a target for receiving input values from the parent.
Click to reveal answer
beginner
How do you use the @Input decorator in a child component?
You import <code>@Input</code> from <code>@angular/core</code> and add it before a property declaration in the child component class. This property will then receive data from the parent component's template.
Click to reveal answer
intermediate
Can the @Input property name be different from the attribute name used in the parent template?
Yes. You can provide an alias inside the @Input decorator like @Input('aliasName'). The parent uses the alias name in its template, while the child uses the property name internally.
Click to reveal answer
beginner
What happens if the parent does not provide a value for an @Input property?
The @Input property in the child component will be undefined unless it has a default value set in the child component class.
Click to reveal answer
intermediate
Why is the @Input decorator important for component communication?
It enables clear, one-way data flow from parent to child components, making the app easier to understand and maintain by separating concerns and avoiding direct manipulation of child internals.
Click to reveal answer
What does the @Input decorator do in Angular?
AAllows a parent to send data to a child component
BSends data from child to parent
CDefines a service for dependency injection
DCreates a new Angular module
✗ Incorrect
The @Input decorator marks a property in the child component to receive data from the parent.
How do you import the @Input decorator?
Aimport { Input } from '@angular/common';
Bimport { Input } from '@angular/forms';
Cimport { Input } from '@angular/core';
Dimport { Input } from '@angular/router';
✗ Incorrect
The @Input decorator is imported from @angular/core.
If you want to use a different name for the input property in the parent template, what do you do?
AChange the property name in the parent component class
BUse <code>@Input('aliasName')</code> in the child component
CUse <code>@Output</code> instead
DRename the child component selector
✗ Incorrect
You can provide an alias name inside the @Input decorator to use a different attribute name in the parent template.
What will be the value of an @Input property if the parent does not bind any value?
AZero
Bnull automatically
CAn empty string
Dundefined unless a default is set
✗ Incorrect
If the parent does not provide a value, the @Input property is undefined unless the child sets a default.
Which direction does data flow when using @Input?
AFrom parent to child
BFrom child to parent
CBetween sibling components
DFrom service to component
✗ Incorrect
@Input is used for one-way data flow from parent component to child component.
Explain how the @Input decorator works to pass data from a parent to a child component in Angular.
Think about how the parent template uses the child selector with property binding.
You got /4 concepts.
Describe a scenario where you would use an alias with the @Input decorator and how to implement it.
This helps when you want clearer or different naming in the parent template.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the @Input decorator in Angular?
easy
A. To define a route in Angular
B. To send data from a child component to its parent component
C. To create a new Angular service
D. To allow a child component to receive data from its parent component
Solution
Step 1: Understand the role of @Input
The @Input decorator is used to mark a property in a child component that can receive data from its parent.
Step 2: Compare options with the concept
Only To allow a child component to receive data from its parent component correctly describes this data flow from parent to child. Options B, C, and D describe other unrelated Angular features.
Final Answer:
To allow a child component to receive data from its parent component -> Option D
Quick Check:
@Input passes data parent to child [OK]
Hint: Remember: @Input means data flows into child [OK]
Common Mistakes:
Confusing @Input with @Output
Thinking @Input sends data up to parent
Mixing @Input with services or routing
2. Which of the following is the correct syntax to declare an @Input property named title in a child component?
easy
A. input title: string;
B. @Input() title: string;
C. @Output() title: string;
D. Input() title: string;
Solution
Step 1: Recall correct @Input syntax
In Angular, to declare an input property, you use @Input() decorator before the property declaration.
Step 2: Check each option
@Input() title: string; correctly uses @Input() with the property name and type. Options A and D miss the decorator syntax, and C uses @Output() which is for event emitters, not inputs.
Final Answer:
@Input() title: string; -> Option B
Quick Check:
Decorator syntax is @Input() [OK]
Hint: Always use @Input() decorator before property [OK]
5. You have a parent component with a property user = {name: 'Alice', age: 30}. You want to pass only the name to a child component using @Input. Which is the best way to do this in the parent template?
hard
A. <child-comp [userName]="user.name"></child-comp>
B. <child-comp [userName]="user"></child-comp>
C. <child-comp userName="user.name"></child-comp>
D. <child-comp [userName]="user['age']"></child-comp>
Solution
Step 1: Understand the data to pass
The parent wants to pass only the name property from the user object, not the whole object.
Step 2: Check each option for correct binding
<child-comp [userName]="user.name"></child-comp> correctly binds user.name to the child's userName input. <child-comp [userName]="user"></child-comp> passes the whole object, not just the name. <child-comp userName="user.name"></child-comp> passes the string literal 'user.name' instead of the value. <child-comp [userName]="user['age']"></child-comp> passes the age, not the name.
Final Answer:
<child-comp [userName]="user.name"></child-comp> -> Option A
Quick Check:
Bind exact property with [inputProp]="object.prop" [OK]
Hint: Bind specific property with [inputProp]="object.prop" [OK]
Common Mistakes:
Passing whole object instead of specific property
Using quotes without brackets causing string literal
Passing wrong property like age instead of name
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.