0
0
Angularframework~20 mins

Input signals and model signals in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Signal Mastery in Angular
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when an input signal changes in Angular?

Consider an Angular standalone component that receives an input signal. What is the behavior when the input signal value changes?

Angular
import { Component, Input, signal } from '@angular/core';

@Component({
  selector: 'app-counter',
  standalone: true,
  template: `
    <p>Count: {{ count() }}</p>
  `
})
export class CounterComponent {
  @Input() count = signal(0);
}
AThe component automatically updates the displayed count when the input signal changes.
BThe component requires manual subscription to the signal to update the display.
CThe component does not update because signals cannot be passed as inputs.
DThe component updates only if a lifecycle hook manually triggers change detection.
Attempts:
2 left
💡 Hint

Think about how Angular signals propagate changes automatically.

state_output
intermediate
2:00remaining
What is the output of this Angular component using model signals?

Given the following Angular component code, what will be displayed after the button is clicked twice?

Angular
import { Component, signal } from '@angular/core';

@Component({
  selector: 'app-clicker',
  standalone: true,
  template: `
    <p>Clicks: {{ clicks() }}</p>
    <button (click)="increment()">Click me</button>
  `
})
export class ClickerComponent {
  clicks = signal(0);

  increment() {
    this.clicks.update(c => c + 1);
  }
}
AClicks: 0
BClicks: undefined
CClicks: 1
DClicks: 2
Attempts:
2 left
💡 Hint

Each button click calls the increment method which updates the signal.

📝 Syntax
advanced
2:00remaining
Which option correctly defines an input signal in Angular?

Choose the correct syntax to define an input signal property in an Angular standalone component.

A@Input() count = signal(0);
B@Input signal count = 0;
C@Input() count: Signal<number> = signal(0);
Dcount = @Input(signal(0));
Attempts:
2 left
💡 Hint

Remember to use the correct TypeScript type annotation and decorator syntax.

🔧 Debug
advanced
2:00remaining
Why does this Angular component fail to update when the input signal changes?

Examine the code below. The component receives an input signal but does not update the displayed value when the input changes. What is the cause?

Angular
import { Component, Input, signal } from '@angular/core';

@Component({
  selector: 'app-display',
  standalone: true,
  template: `
    <p>Value: {{ value() }}</p>
  `
})
export class DisplayComponent {
  @Input() value = signal(0);

  ngOnChanges() {
    // No code here
  }
}
AThe input signal is reassigned instead of updated, breaking reactivity.
BThe component does not import 'Signal' type, causing a runtime error.
CThe template uses value() which is invalid syntax for signals.
DThe component lacks a manual subscription to the input signal.
Attempts:
2 left
💡 Hint

Check how the input signal is handled and whether it is replaced or updated.

🧠 Conceptual
expert
3:00remaining
How do model signals differ from input signals in Angular's reactive system?

Choose the statement that best describes the difference between model signals and input signals in Angular.

AInput signals are mutable inside the component, but model signals are read-only from outside.
BModel signals are owned and updated inside the component, while input signals come from outside and should not be mutated internally.
CModel signals and input signals are identical and interchangeable in Angular components.
DInput signals automatically trigger change detection, but model signals require manual triggering.
Attempts:
2 left
💡 Hint

Think about ownership and mutation rights of signals in component design.