Bird
Raised Fist0
Angularframework~10 mins

Signal vs observable comparison in Angular - Visual Side-by-Side Comparison

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Concept Flow - Signal vs observable comparison
Create Signal
Set initial value
Update Signal value
Signal auto-triggers
UI updates/reacts
Signals hold a value and auto-update dependents when changed. Observables emit streams of values that subscribers listen to and react.
Execution Sample
Angular
import { signal } from '@angular/core';
import { Observable } from 'rxjs';

const count = signal(0);
const count$ = new Observable(subscriber => {
  subscriber.next(0);
});

count.set(1);
count$.subscribe(value => console.log(value));
Shows creating a signal and an observable with initial values, updating the signal, and subscribing to the observable.
Execution Table
StepActionSignal ValueObservable EmissionEffect
1Create signal with 00N/ASignal holds 0
2Create observable emitting 000 emittedSubscribers can listen
3Update signal to 110 (no new emission)Signal triggers dependents
4Subscribe to observable10 receivedSubscriber logs 0
5Observable emits 111 emittedSubscriber logs 1
6Signal auto-updates UI11 emittedUI reflects signal value 1
💡 Execution stops after observable emits and signal updates UI
Variable Tracker
VariableStartAfter Step 3After Step 5Final
count (signal)0111
count$ (observable)no emission0 emitted1 emitted1 emitted
Key Moments - 2 Insights
Why does the signal update UI automatically but observable needs subscription?
Signals hold a current value and auto-notify dependents on change (see Step 3 and 6). Observables emit values over time and require explicit subscription to react (see Step 4).
Can signals emit multiple values like observables?
Signals hold one current value that updates. Observables can emit many values over time. Signals are simpler for state, observables for streams (see Steps 1-5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the signal value after Step 3?
A0
B1
Cundefined
Dnull
💡 Hint
Check the 'Signal Value' column at Step 3 in the execution table
At which step does the observable emit its first value?
AStep 2
BStep 3
CStep 1
DStep 4
💡 Hint
Look at the 'Observable Emission' column to find the first emission
If the signal value changes, what happens automatically?
ANothing happens
BSubscribers must manually check
CUI and dependents auto-update
DObservable emits new value
💡 Hint
Refer to Step 6 in the execution table showing signal effect
Concept Snapshot
Signal vs Observable in Angular:
- Signal holds a single reactive value.
- Observable emits multiple values over time.
- Signals auto-update dependents/UI on change.
- Observables require subscription to react.
- Use signals for state, observables for event streams.
Full Transcript
This visual compares Angular signals and observables. Signals hold a current value and automatically notify dependents when updated, causing UI to refresh. Observables emit streams of values that subscribers listen to and react upon. The execution table shows creating a signal and observable, updating the signal, subscribing to the observable, and how each triggers reactions. Key moments clarify why signals auto-update UI while observables need subscriptions, and the difference in value emission. The quiz tests understanding of signal values, observable emissions, and automatic updates. This helps beginners see how signals and observables behave differently in Angular.

Practice

(1/5)
1. Which statement best describes an Angular signal compared to an observable?
easy
A. A signal requires manual subscription to receive updates.
B. A signal handles multiple asynchronous events over time.
C. A signal holds a single reactive value and updates UI automatically.
D. A signal is used only for HTTP requests.

Solution

  1. Step 1: Understand what a signal represents

    Signals hold a single reactive value that updates the UI automatically when changed.
  2. Step 2: Compare with observable behavior

    Observables handle streams of data over time and require subscriptions, unlike signals.
  3. Final Answer:

    A signal holds a single reactive value and updates UI automatically. -> Option C
  4. Quick Check:

    Signal = single reactive value [OK]
Hint: Signals hold one value; observables handle streams [OK]
Common Mistakes:
  • Thinking signals handle multiple async events like observables
  • Believing signals require subscriptions
  • Confusing signals with HTTP request handlers
2. Which of the following is the correct way to create a signal in Angular?
easy
A. const count = new Observable(0);
B. const count = signal(0);
C. const count = subscribe(0);
D. const count = createObservable(0);

Solution

  1. Step 1: Recall Angular signal creation syntax

    Signals are created using the signal() function with an initial value.
  2. Step 2: Identify incorrect options

    Observable creation uses new Observable(), subscribe is a method, and createObservable() is not valid.
  3. Final Answer:

    const count = signal(0); -> Option B
  4. Quick Check:

    signal() creates signals [OK]
Hint: Use signal() function to create signals [OK]
Common Mistakes:
  • Using new Observable() to create a signal
  • Confusing subscribe() with signal creation
  • Using non-existent createObservable() function
3. Given the code below, what will be logged to the console?
const count = signal(1);
count.set(5);
console.log(count());
medium
A. 1
B. An error because signals cannot be set
C. undefined
D. 5

Solution

  1. Step 1: Understand signal value update

    The signal is created with initial value 1, then updated to 5 using set().
  2. Step 2: Check the value returned by calling the signal

    Calling count() returns the current value, which is 5 after set().
  3. Final Answer:

    5 -> Option D
  4. Quick Check:

    Signal value after set() = 5 [OK]
Hint: Calling signal() returns current value [OK]
Common Mistakes:
  • Assuming initial value remains after set()
  • Thinking signals cannot be updated
  • Confusing signal() call with observable subscription
4. What is wrong with this Angular code using an observable?
const obs = new Observable(subscriber => {
  subscriber.next(1);
});
obs.next(2);
medium
A. Observables do not have a next() method on the instance.
B. Observable must be created with signal() instead.
C. Subscriber function cannot call next().
D. Observable must be subscribed before calling next().

Solution

  1. Step 1: Understand Observable instance methods

    Observable instances do not have a next() method; next() is called on the subscriber inside the constructor.
  2. Step 2: Identify misuse of next() outside subscriber

    Calling obs.next(2) is invalid and causes an error.
  3. Final Answer:

    Observables do not have a next() method on the instance. -> Option A
  4. Quick Check:

    next() is on subscriber, not observable instance [OK]
Hint: next() is called inside subscriber, not on observable [OK]
Common Mistakes:
  • Trying to call next() on observable instance
  • Confusing signal() with observable creation
  • Believing subscription is needed before next()
5. You want to manage a simple counter state that updates the UI immediately when changed. Which approach is best and why?
Option A: Use a signal to hold the counter value.
Option B: Use an observable and subscribe to updates.
Option C: Use a Promise to fetch the counter value.
Option D: Use a BehaviorSubject without subscription.
hard
A. Signal is best because it holds a single reactive value and updates UI automatically.
B. Observable is best because it handles multiple async events efficiently.
C. Promise is best because it resolves once with the counter value.
D. BehaviorSubject without subscription updates UI automatically.

Solution

  1. Step 1: Identify the requirement for simple immediate UI update

    A simple counter state that updates UI immediately fits the signal use case.
  2. Step 2: Compare other options

    Observable requires subscription and is better for streams; Promise resolves once; BehaviorSubject needs subscription to update UI.
  3. Final Answer:

    Signal is best because it holds a single reactive value and updates UI automatically. -> Option A
  4. Quick Check:

    Simple state + auto UI update = signal [OK]
Hint: Use signals for simple reactive state, observables for streams [OK]
Common Mistakes:
  • Choosing observable for simple state without subscription
  • Using Promise for reactive UI updates
  • Assuming BehaviorSubject updates UI without subscription