4

Can someone explain to me why Angular 2 requires the RxJS library and how it exactly relates to Observables & Angular 2

Ray Kim
  • 1,931
  • 1
  • 13
  • 25

1 Answers1

2

RxJS is the reactive programming library for JavaScript that Angular2 uses.

In fact the Observable class comes from this library.

For example, the EventEmitter class of Angular2 (which is an hot observable) extends the Subject class from RxJS. See these lines in the source:

Some classes within the form and HTTP supports also leverage Observable from this library:

To summarize, when you use the following features of Angular2, you indirectly use the Rxjs library:

  • Use component events
  • Use change detection of form controls
  • Use HTTP
  • ...

What is great with observables is that you can interconnect them to create your asynchronous data streams. It's very powerful and go further than what promises provide...

You can notice that you can create Observables by your own if you want as well.

Otherwise if you're looking for a great introduction to Reactive Programming, you could have a look at this great article: https://gist.github.com/staltz/868e7e9bc2a7b8c1f754.

Hoping it answers your question since the latter was a bit wide. Thierry

Thierry Templier
  • 198,364
  • 44
  • 396
  • 360