0
0
Angularframework~20 mins

Signal vs observable comparison in Angular - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Signal vs Observable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Difference in update behavior between Signal and Observable

In Angular, both Signals and Observables can be used to react to data changes. Which statement best describes how Signals differ from Observables in terms of update behavior?

ASignals require manual subscription to receive updates, while Observables update automatically without subscriptions.
BSignals emit multiple values over time asynchronously, while Observables hold a single synchronous value.
CSignals update synchronously and cache their latest value, while Observables emit asynchronously and do not cache values by default.
DSignals and Observables behave identically in update timing and caching.
Attempts:
2 left
💡 Hint

Think about how each handles the timing of updates and whether they keep the last value accessible.

component_behavior
intermediate
2:00remaining
Component rendering with Signal vs Observable

Consider an Angular component that displays a counter value. The counter is provided as a Signal in one version and as an Observable in another. What difference in rendering behavior will you observe?

AThe Signal-based component updates the view immediately on value change, while the Observable-based component requires an async pipe or subscription to update.
BThe Observable-based component updates the view immediately without any extra code, while the Signal-based component needs manual subscription.
CBoth components update the view only when manually triggered by a button click.
DNeither component updates the view automatically; both require manual change detection calls.
Attempts:
2 left
💡 Hint

Think about how Angular templates handle Signals and Observables differently.

📝 Syntax
advanced
2:00remaining
Correct syntax to create a Signal and an Observable

Which option shows the correct way to create a Signal and an Observable that emit numbers starting from 0 every second?

A
const countSignal = new Signal(0);
const countObservable = new Observable(1000);
B
const countSignal = signal(0);
const countObservable = interval(1000);
C
const countSignal = signal(() => 0);
const countObservable = interval();
D
const countSignal = signal(0, 1000);
const countObservable = Observable.interval(1000);
Attempts:
2 left
💡 Hint

Remember the Angular Signal creation function and RxJS interval syntax.

🔧 Debug
advanced
2:00remaining
Why does this Observable subscription not update the view?

Given this Angular component code snippet, why does the view not update when count$ emits new values?

count$ = interval(1000);

ngOnInit() {
  this.count$.subscribe(value => {
    this.currentCount = value;
  });
}
ABecause the subscription is missing an unsubscribe, causing a memory leak and blocking updates.
BBecause <code>subscribe</code> must be called inside the constructor, not ngOnInit.
CBecause <code>interval</code> does not emit any values without a start call.
DBecause <code>currentCount</code> is not a Signal, Angular does not detect changes automatically.
Attempts:
2 left
💡 Hint

Think about Angular's change detection and how it tracks changes to variables.

state_output
expert
2:00remaining
Output of combined Signal and Observable updates

Consider this Angular component snippet:

const countSignal = signal(0);
const countObservable = interval(1000);

countObservable.subscribe(value => {
  countSignal.set(value);
});

console.log(countSignal());

What will be logged immediately after this code runs?

A0
B1
Cundefined
DThrows an error because Signals cannot be set inside subscriptions
Attempts:
2 left
💡 Hint

Think about when the Observable emits its first value relative to the console.log call.