Bird
0
0

Which of the following is the correct way to create a new observable in Angular?

easy📝 Syntax Q12 of 15
Angular - RxJS and Observables Fundamentals
Which of the following is the correct way to create a new observable in Angular?
Aconst obs = new Observable(subscriber => { subscriber.next('Hello'); });
Bconst obs = Observable.create('Hello');
Cconst obs = new Observable.next('Hello');
Dconst obs = Observable('Hello');
Step-by-Step Solution
Solution:
  1. Step 1: Recall Observable creation syntax

    Use new Observable() with a function receiving a subscriber.
  2. Step 2: Check each option

    Only const obs = new Observable(subscriber => { subscriber.next('Hello'); }); correctly uses new Observable(subscriber => subscriber.next(...)).
  3. Final Answer:

    const obs = new Observable(subscriber => { subscriber.next('Hello'); }); -> Option A
  4. Quick Check:

    Correct syntax uses new Observable with subscriber function [OK]
Quick Trick: Use new Observable(subscriber => ...) to create [OK]
Common Mistakes:
MISTAKES
  • Using Observable.create which is deprecated
  • Calling next on Observable directly
  • Trying to call Observable as a function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes