0
0
Angularframework~5 mins

@Input decorator for parent to child in Angular - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
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
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';
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
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
Which direction does data flow when using @Input?
AFrom parent to child
BFrom child to parent
CBetween sibling components
DFrom service to 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.