Bird
0
0

After migrating from observable to signal, this code throws an error:

medium📝 Debug Q7 of 15
Angular - Signals
After migrating from observable to signal, this code throws an error:
const data = signal(null);

this.data$.subscribe(value => data.set(value));

What is the issue?
AYou must use <code>update()</code> instead of <code>set()</code>.
BMixing observable subscription with signal defeats signal benefits.
CThe initial value of signal cannot be null.
DSignals cannot be set inside subscriptions.
Step-by-Step Solution
Solution:
  1. Step 1: Identify mixing patterns

    Subscribing to observable and setting signal manually mixes reactive patterns.
  2. Step 2: Understand signal migration goal

    Signals replace subscriptions by providing synchronous reactive values.
  3. Final Answer:

    Mixing observable subscription with signal defeats signal benefits. -> Option B
  4. Quick Check:

    Avoid mixing observables and signals = D [OK]
Quick Trick: Avoid subscribing to observables when using signals [OK]
Common Mistakes:
  • Thinking signals cannot be set inside subscriptions
  • Believing initial null value causes error
  • Confusing set() and update() usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes