0
0
Angularframework~20 mins

Signal-based components in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Signal Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Angular signal-based component?
Consider this Angular standalone component using signals. What will be displayed when the component renders?
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);
  }
}
AA button labeled 'Increment' and a paragraph showing 'Count: 0' but does not update on clicks.
BA button labeled 'Increment' but no count is displayed.
CA button labeled 'Increment' and a paragraph showing 'Count: 1' initially, increasing by 1 each click.
DA button labeled 'Increment' and a paragraph showing 'Count: 0' initially, increasing by 1 each click.
Attempts:
2 left
💡 Hint
Remember that signals hold reactive values and the template calls the signal as a function to get the current value.
state_output
intermediate
2:00remaining
What is the value of the signal after these updates?
Given this Angular component using signals, what is the final value of status() after the code runs?
Angular
import { Component, signal } from '@angular/core';

@Component({
  selector: 'app-status',
  standalone: true,
  template: `<p>Status: {{ status() }}</p>`
})
export class StatusComponent {
  status = signal('idle');

  constructor() {
    this.status.set('loading');
    this.status.update(s => s + '...');
    this.status.set('done');
  }
}
A'done'
B'loading...'
C'idle'
D'done...'
Attempts:
2 left
💡 Hint
Signals update immediately when set or updated. The last set call determines the final value.
📝 Syntax
advanced
2:00remaining
Which option causes a syntax error in signal usage?
Identify which code snippet will cause a syntax error when defining or updating a signal in Angular.
A
const count = signal(0);
count.update(c =&gt; c + 1);
B
const count = signal(0);
count.set(count + 1);
C
const count = signal(0);
count.update(c =&gt; c + 1); count.set(5);
D
const count = signal(0)
count.update(c =&gt; c + 1);
Attempts:
2 left
💡 Hint
Remember that set expects a value, not a signal function or signal itself.
🔧 Debug
advanced
2:00remaining
Why does this signal not update the template?
Given this Angular component, 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 component is missing the @Injectable decorator.
Attempts:
2 left
💡 Hint
Signals must be called as functions in templates to get their current value.
🧠 Conceptual
expert
3:00remaining
What happens if you update a signal inside a signal's computed function?
Consider this Angular code snippet using signals and computed signals. What will happen when the component initializes?
Angular
import { Component, signal, computed } from '@angular/core';

@Component({
  selector: 'app-loop',
  standalone: true,
  template: `<p>Value: {{ value() }}</p>`
})
export class LoopComponent {
  count = signal(0);
  value = computed(() => {
    if (this.count() < 3) {
      this.count.update(c => c + 1);
    }
    return this.count();
  });
}
AThe component will render 'Value: 0' because updates inside computed are ignored.
BThe component will render 'Value: 3' after incrementing count three times without errors.
CThe component will cause a runtime error due to infinite signal update loop.
DThe component will render 'Value: 1' and stop updating.
Attempts:
2 left
💡 Hint
Signals and computed functions should not cause side effects like updating signals inside computed.