0
0
Angularframework~20 mins

Signals as modern state primitive in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Signal Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
Understanding signal updates in Angular 17+
Given the following Angular component using signals, what will be the rendered output after clicking the button twice?
Angular
import { Component, signal } from '@angular/core';

@Component({
  selector: 'app-counter',
  standalone: true,
  template: `<button (click)="increment()">Increment</button><p>Count: {{ count() }}</p>`
})
export class CounterComponent {
  count = signal(0);

  increment() {
    this.count.update(c => c + 1);
  }
}
ACount: 2
BCount: 1
CCount: 0
DCount: NaN
Attempts:
2 left
💡 Hint
Remember that each click calls the increment method which updates the signal by adding 1.
state_output
intermediate
1:30remaining
Signal derived state behavior
What is the value of fullName() after the following code runs?
Angular
import { signal, computed } from '@angular/core';

const firstName = signal('Jane');
const lastName = signal('Doe');
const fullName = computed(() => `${firstName()} ${lastName()}`);

firstName.set('John');
A"John Jane"
B"Doe John"
C"Jane Doe"
D"John Doe"
Attempts:
2 left
💡 Hint
Signals update reactively, so computed values reflect the latest signal states.
📝 Syntax
advanced
1:30remaining
Identify the syntax error in signal usage
Which option contains a syntax error when declaring and updating a signal in Angular?
A
const count = signal(0);
count.set(count() + 1);
B
const count = signal(0);
count.update(c =&gt; c + 1);
C
const count = signal(0);
count = 1;
D
;)1 + c &gt;= c(etadpu.tnuoc
;)0(langis = tnuoc tsnoc
Attempts:
2 left
💡 Hint
Signals are immutable references; you cannot assign a new value directly to the signal variable.
🔧 Debug
advanced
2:00remaining
Why does the signal not update the template?
Consider this Angular component code. Why does the displayed count not update when the button is clicked?
Angular
import { Component, signal } from '@angular/core';

@Component({
  selector: 'app-broken-counter',
  standalone: true,
  template: `<button (click)="increment()">Increment</button><p>Count: {{ count }}</p>`
})
export class BrokenCounterComponent {
  count = signal(0);

  increment() {
    this.count.update(c => c + 1);
  }
}
AThe template uses {{ count }} instead of calling the signal as a function {{ count() }}.
BThe signal is not initialized properly with signal(0).
CThe increment method does not update the signal correctly.
DThe button click event is not bound properly.
Attempts:
2 left
💡 Hint
Signals are functions and must be called to get their current value in templates.
🧠 Conceptual
expert
2:30remaining
Signal behavior with nested updates
What will be the final value of counter() after running this code snippet?
Angular
import { signal } from '@angular/core';

const counter = signal(0);

counter.update(c => {
  counter.update(c2 => c2 + 1);
  return c + 1;
});
A0
B1
C2
DThrows an error due to nested updates
Attempts:
2 left
💡 Hint
Consider how nested update calls affect the signal's value sequentially.