Can someone explain to me why Angular 2 requires the RxJS library and how it exactly relates to Observables & Angular 2
-
are you talking about http observable ? – Pardeep Jain Jan 20 '16 at 17:27
1 Answers
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:
- https://github.com/angular/angular/blob/master/modules/angular2/src/facade/async.ts#L8
- https://github.com/angular/angular/blob/master/modules/angular2/src/facade/async.ts#L109
Some classes within the form and HTTP supports also leverage Observable
from this library:
- HTTP
- Form support
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 Observable
s 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

- 198,364
- 44
- 396
- 360