In this article, we will look at the many different methods of creating Observables provided to us by RxJS.

Observables are the foundation of RxJS.

There are two main methods to create Observables in RxJS. Subjects and Operators. We will take a look at both of these!

What is an Observable?

Observables are like functions with zero arguments that push multiple values to their Observers, either synchronously or asynchronously.

Also read, What Is Observable In RxJS

Creating Custom Observable

First, we need to import it from rxjs:

import { Observable } from "rxjs/Observable";

Creating Custom Observable:

// Creating Observable
const obs$ = Observable.create((observer) => {
  observer.next(1);
  observer.next(2);
  //Will Thorow error
 //observer.error(new Error("Limit Exceed"));
  observer.next(3);
  //To stop execution after 
  observer.complete();
});

//Handle Subscription
custObs1.subscribe(
      (res) => {
        console.log(res);
        this._desingUtility.print(res, "elContainer");
      },
      (error) => {
        this.status = "error";
      },
      () => {
        this.status = "completed";
      }
    );

In the above example, once we subscribe to observable we will start getting observable data, This will appear like below in your browser console:

//OutPut : 
1
2
3

Topics covered:

Found this article helpful?

TutsCoder tutorials are free and ad-light — supported by readers like you. Buy me a coffee (or two ☕☕) as a token of appreciation and help keep Angular & Node.js content coming!

One-time. No subscription. 100% optional. 🙏 Every coffee counts!

Leave a Comment

Your email will not be published. Spam-free zone. ✌️

Available for Projects

Need Help With Your
Angular or Node.js Project?

7+ years of MEAN Stack experience. I build scalable Angular 21 apps, Node.js APIs, and SaaS products — delivered on time, every time.

7+ Years MEAN Stack Angular 21 + Nx Expert 20+ Projects Delivered Remote / Freelance