0
0
Angularframework~20 mins

Migrating from observables to signals in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Signal Migration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
Understanding signal updates vs observable subscriptions

Consider an Angular component migrating from an observable to a signal. Which behavior correctly describes how the component updates when the signal changes compared to the observable?

ASignals do not trigger component updates; only observables do.
BThe component automatically re-renders when the signal value changes without manual subscription management.
CThe component requires manual subscription and unsubscription to update when the signal changes.
DThe component updates only when the signal is explicitly refreshed by calling a method.
Attempts:
2 left
💡 Hint

Think about how signals simplify reactive updates compared to observables.

📝 Syntax
intermediate
2:00remaining
Correct syntax for creating a signal from an observable

Which code snippet correctly creates a signal from an observable using Angular's toSignal function?

Aconst countSignal = countObservable.toSignal(0);
Bconst countSignal = toSignal(countObservable, 0);
Cconst countSignal = toSignal(countObservable, { initialValue: 0 });
Dconst countSignal = toSignal(countObservable);
Attempts:
2 left
💡 Hint

Check the correct way to pass options to toSignal.

🔧 Debug
advanced
2:00remaining
Identifying the error when migrating observable subscription to signal

Given this Angular component code migrating from observable to signal, what error will occur?

import { Component, signal } from '@angular/core';
import { interval } from 'rxjs';
import { toSignal } from '@angular/core/rxjs-interop';

@Component({
  selector: 'app-timer',
  template: `{{ timer() }}`
})
export class TimerComponent {
  timer = toSignal(interval(1000));
}
ATypeError: toSignal requires an initialValue option for cold observables.
BSyntaxError: Missing parentheses in toSignal call.
CNo error; the code works as expected.
DRuntimeError: interval is not a function.
Attempts:
2 left
💡 Hint

Consider what happens when converting a cold observable like interval to a signal.

state_output
advanced
2:00remaining
Result of signal value after observable emits

What is the value of countSignal() after 3 seconds given this code?

import { signal } from '@angular/core';
import { interval } from 'rxjs';
import { toSignal } from '@angular/core/rxjs-interop';

const countObservable = interval(1000);
const countSignal = toSignal(countObservable, { initialValue: 0 });

setTimeout(() => {
  console.log(countSignal());
}, 3000);
A2
B0
Cundefined
DThrows an error
Attempts:
2 left
💡 Hint

Remember how interval emits values every second starting from 0.

🧠 Conceptual
expert
3:00remaining
Key advantage of signals over observables in Angular migration

What is the main advantage of migrating from observables to signals in Angular applications?

ASignals allow multiple subscribers to share the same data stream more efficiently than observables.
BSignals replace the need for Angular templates by rendering directly in TypeScript.
CSignals enable asynchronous data fetching without any need for Angular lifecycle hooks.
DSignals provide automatic change detection and simpler state management without manual subscriptions.
Attempts:
2 left
💡 Hint

Think about how signals reduce boilerplate compared to observables.