0Pricing
Angular Academy · Lesson

Observables and Subscriptions

Create and subscribe to observable streams.

What is an Observable

An Observable is a lazy stream of values over time. Nothing happens until you subscribe. It can emit zero or more values, then either complete or error.

RxJS is the reactive library Angular ships for handling async work like HTTP, events, and timers.

Creating an Observable

The Observable constructor takes a subscriber function. You call next() to emit, complete() to finish, error() to fail.

import { Observable } from 'rxjs';

const numbers$ = new Observable<number>(subscriber => {
  subscriber.next(1);
  subscriber.next(2);
  subscriber.next(3);
  subscriber.complete();
});

All lessons in this course

  1. Observables and Subscriptions
  2. Subjects and BehaviorSubject
  3. Unsubscribing and Memory Leaks
  4. The async Pipe
← Back to Angular Academy