Challenge - 5 Problems
Angular Input Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What will be displayed by the child component?
Given the parent passes a value to the child using @Input, what will the child component render?
Angular
/* Parent component template */ <app-child [message]="parentMessage"></app-child> /* Parent component class */ export class ParentComponent { parentMessage = 'Hello from Parent'; } /* Child component class */ import { Component, Input } from '@angular/core'; @Component({ selector: 'app-child', template: `<p>{{ message }}</p>` }) export class ChildComponent { @Input() message: string = ''; }
Attempts:
2 left
💡 Hint
Check how the @Input decorator passes data from parent to child.
✗ Incorrect
The @Input decorator allows the child component to receive data from the parent. Here, the parent passes 'parentMessage' to the child's 'message' property, so the child displays 'Hello from Parent'.
📝 Syntax
intermediate1:30remaining
Which option correctly declares an @Input property in Angular?
Select the correct syntax to declare an @Input property named 'title' in a child component.
Attempts:
2 left
💡 Hint
Remember the exact decorator name and syntax in Angular.
✗ Incorrect
The correct syntax uses the @Input() decorator imported from '@angular/core' followed by the property declaration. Only option A uses the correct decorator and syntax.
❓ state_output
advanced2:30remaining
What is the output when the parent changes the input value after initialization?
If the parent changes the value bound to the child's @Input property after the child is initialized, what will the child display?
Angular
/* Parent component template */ <app-child [count]="parentCount"></app-child> /* Parent component class */ export class ParentComponent { parentCount = 1; increment() { this.parentCount++; } } /* Child component class */ import { Component, Input } from '@angular/core'; @Component({ selector: 'app-child', template: `<p>{{ count }}</p>` }) export class ChildComponent { @Input() count: number = 0; }
Attempts:
2 left
💡 Hint
Consider how Angular's change detection updates @Input properties.
✗ Incorrect
Angular automatically updates the child's @Input property when the parent changes the bound value. The child template reflects the updated value.
🔧 Debug
advanced2:30remaining
Why does the child component not receive the input value?
Given the code below, why does the child component display nothing even though the parent passes a value?
Angular
/* Parent template */ <app-child message="Hello"></app-child> /* Child component */ import { Component, Input } from '@angular/core'; @Component({ selector: 'app-child', template: `<p>{{ message }}</p>` }) export class ChildComponent { @Input() message: string = ''; }
Attempts:
2 left
💡 Hint
Check how Angular binds input properties in templates.
✗ Incorrect
Without square brackets, Angular treats the value as a string literal, not a binding. To pass a variable or expression, square brackets are required.
🧠 Conceptual
expert3:00remaining
What happens if the @Input property name differs from the binding name in the parent template?
Consider the child component has @Input('aliasName') actualName: string; and the parent binds [aliasName]="value". What will happen?
Angular
/* Child component */ import { Component, Input } from '@angular/core'; @Component({ selector: 'app-child', template: `<p>{{ actualName }}</p>` }) export class ChildComponent { @Input('aliasName') actualName: string = ''; } /* Parent template */ <app-child [aliasName]="parentValue"></app-child>
Attempts:
2 left
💡 Hint
Think about how @Input can rename input properties.
✗ Incorrect
The string parameter in @Input('aliasName') tells Angular to bind the input property to 'aliasName' from the parent, even though the internal property is 'actualName'. This allows renaming inputs.