RxJS — Subjects

Jawadhasan
7 min readNov 11, 2023
Photo by Jainath Ponnala on Unsplash

Introduction

In previous posts we’ve discussed RxJS and saw few examples to understand how to use those in our angular applications

You can check the earlier posts in following links

Today, we’ll discuss Subject which is very useful and powerful feature of RxJS.

We’ll start simple with few examples mostly around the subject theory and then later we’ll put subject to good use by creating an EventBus and an Observable Service which will allow us to send data and notifications between components.

Let’s start with the basics first.

A key purpose of subject is to send out notifications.

A subject is a special type of observable that can multicast a value or event to multiple subscriber, meaning it provides a way to send one or more data values to listeners. Any component or service that subscribes to the subject’s observable will receive notification.

A subject is also an observer. An observer allow us to push new data into observable sequence. Any component or other services can feed new values into the subject, using its next method. The new value then multi-cast to all subscribers.

--

--

Jawadhasan
Jawadhasan

Written by Jawadhasan

Software Solutions Team Lead | Cloud Architect | Solutions Architect

No responses yet