Bird
0
0

What is wrong with this Angular code using an observable?

medium📝 Debug Q14 of 15
Angular - Signals
What is wrong with this Angular code using an observable?
const obs = new Observable(subscriber => {
  subscriber.next(1);
});
obs.next(2);
AObservables do not have a next() method on the instance.
BObservable must be created with signal() instead.
CSubscriber function cannot call next().
DObservable must be subscribed before calling next().
Step-by-Step Solution
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]
Quick Trick: 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()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes