The RxJS Library
Learn about the different types of operators available in the RxJS library.
We'll cover the following
In this lesson, we will learn about the RxJS library, which provides the observable operators, and learn about some of them through examples.
As mentioned previously, Angular comes with a peer dependency on RxJS, the JavaScript flavor of the ReactiveX library that allows us to create observables out of a large variety of scenarios, including the following:
Interaction events
Promises
Callback functions
Events
In this sense, reactive programming does not aim to replace asynchronous patterns, such as promises or callbacks. It can leverage them as well to create observable sequences.
RxJS has built-in support for a wide range of composable operators to transform, filter, and combine the resulting event streams. Its API provides convenient methods for observers to subscribe to these streams so that our components can respond accordingly to state changes or input interaction. Let’s see some of these operators in action in the following sections.
Creating observables
We have already learned how to create an observable from a DOM event using the fromEvent
operator. Two other popular operators concerned with observable creation are the of
and from
operators. The of
operator is used to create an observable from values such as numbers:
Get hands-on with 1400+ tech skills courses.