Birth and Connection: Observables

Discover how data streams are born and consumed in Angular. Learn the producer/consumer pattern that powers reactive applications.

Stream ProgressStep 1 of 8
📡
0 EXP

Welcome! Let's explore Observables in Angular. Think of an Observable as a blueprint for a stream of data that unfolds over time.

// Preparing the Data Stream...

Creating an Observable

To create a manual stream, we use the new Observable constructor. This constructor takes a single argument: a function often called the "subscribe" function. This function receives an observer object.

import { Observable } from 'rxjs';

const myStream$ = new Observable(observer => {
  // Logic to emit data goes here
});

It is a convention in the Angular community to append a $ sign to variables that hold Observables (e.g., myStream$).

Stream Analysis

Does code inside 'new Observable' run immediately when defined?

Advanced Stream Simulations

0 EXP

Apply your RxJS knowledge and earn achievements.


Achievements

🏗️
Stream Architect

successfully create an Observable with a producer function.

🔌
Subscription Specialist

Connect a consumer to a stream using .subscribe().

🔄
Lifecycle Logician

Correctly implement next, error, and complete notifications.

Mission: Build and Consume a Stream

Write code to create an Observable that emits at least one value, completes, and has a subscriber to log the output.

Analysis Log:

> Awaiting input...

Challenge: Logical Flow

Drag the RxJS concepts into the correct logical order of operations.

Define Producer (observer.next)
Teardown (complete)
Create (new Observable)
Subscribe (consumer)

Challenge: Complete the Code

Fill in the missing RxJS keywords (Case Sensitive).

const obs$ = new (obs => { obs.('Hi'); }); obs$.(console.log);

Consult The Architect

Dev Community Hub

Peer Project Review

Submit your "Custom Observable" project for code review by other Angular developers.

The Pulse of Angular: Understanding Observables

Angular is inherently reactive. From handling HTTP requests with `HttpClient` to listening for form changes with `ReactiveForms`, Observables are everywhere. At their core, Observables are a pattern for managing asynchronous data streams. But how are they born, and how do we tap into them?

The Producer vs. The Consumer

The most critical concept to grasp is the separation between the **Producer** (the Observable) and the **Consumer** (the Observer/Subscriber).

The Observable (Producer)

"I am a blueprint. I define *what* data to send and *when*. But I am lazy. I don't start working until someone connects to me."

new Observable(observer => {
  observer.next('Data');
})

The Subscription (Consumer)

"I am the trigger. By calling .subscribe(), I tell the producer to start execution and I define *what to do* with the data received."

myObservable.subscribe(
  data => console.log(data)
)

The Three Notifications

An Observable can communicate with its subscriber in three ways:

  • next(value): The standard way to push data. It can be called zero, one, or infinite times.
  • error(err): Signals that something went wrong. This kills the stream immediately. No more data is emitted.
  • complete(): Signals that the stream has finished successfully. No more data is emitted.
Key Takeaway: Observables are "lazy". Unlike Promises, which execute immediately upon creation, code inside `new Observable()` will not run until `.subscribe()` is called. This allows you to define complex data flows without triggering them prematurely.

RxJS & Observable Glossary

Observable
A blueprint for a stream of data. It is a collection of values over time that can be synchronous or asynchronous.
Observer
An object with callbacks (`next`, `error`, `complete`) that listens to the notifications from an Observable.
Subscription
The execution of an Observable. It is primarily used to cancel (unsubscribe) the execution to free up resources.
Emit
The act of sending data from the Observable to the Observer, usually via `observer.next()`.
Stream
A sequence of data elements made available over time.

About the Author

Author's Avatar

TodoTutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of Angular experts, who have years of experience teaching reactive programming.

Verification and Updates

Last reviewed: October 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest Angular and RxJS specifications.

External Resources

Found an error or have a suggestion? Contact us!