Ways to create Observables in RxJS

These are some of the common ways to create Observables in RxJS.

Deepak Pandey
Sep 29 · 2 min read

What is RxJS?

RxJS is a library for reactive programming using Observables, to make it easier to compose asynchronous or callback-based code.

It provides one core type, the Observable, satellite types (Observer, Schedulers, Subjects) and operators inspired by Array#extras (map, filter, reduce, every, etc) to allow handling asynchronous events as collections. (RxJS Docs).

What is Observable?

Basically, Observable is a lazy Push collection of multiple values. They provide a continuous channel of communication in which multiple values of data can be emitted over time.

Angular widely use Observables like in HTTP service and the event system.

RxJS offers a number of functions that can be used to create observables.

  1. Using of function

2. Using from function

passing a promise to from function
passing an array of numbers to from function

3. Using fromEvent function

Passing click event to fromEvent function

4. Using interval function

Passing timer to interval function

These are some of the common ways to create Observables in RxJS.

JavaScript in Plain English

Deepak Pandey

Written by

Angular | Angular JS | JavaScript | Python | Java

JavaScript in Plain English

Learn the web's most important programming language.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade