CORE ANGULAR • LESSON 14 OF 23

RxJS and Signal Interoperability

What you will learn

Use observables for event streams and signals for synchronous reactive state.

  • An observable represents values over time and can model HTTP, router events, user input, and external subscriptions. Operators describe cancellation, transformation, and combination.
  • switchMap cancels the previous inner subscription when a new search value arrives. debounceTime limits rapid input work and distinctUntilChanged skips repeated values.
  • toSignal exposes the latest observable value to signal-based templates. toObservable exposes a signal to an RxJS pipeline. Choose a clear ownership direction.
  • A BehaviorSubject has a current value, but a writable signal is often simpler for synchronous application state in new Angular code.

How it works

1Signal captures query
2Observable debounces
3switchMap cancels old request
4toSignal updates view

Expected result

Typing pauses briefly before search; a newer query cancels the previous search subscription. StudentApi must provide search(query).

Common mistakes

Do not nest subscriptions. Do not use mergeMap when old searches must be cancelled. Always define error behavior because one unhandled error completes an observable chain.

Read the official Angular guide →