Today I’m starting a new series of articles looking at observables in Angular 6 and RxJS 6. Observables is a big subject so I’m going to keep coming back to it.
“RxJS has been rearranged to make it more tree-shakable, ensuring that only the pieces of RxJS that you use are included in your production bundles.” , blog.angular.io. You can learn more about this here.
The following examples follow the new Angular 6 coding styles. They are tree-shakable and future-proof.
of = create an observable from a sequence
The “of” method creates an observable from any sequence. e.g. of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).
Try it out on StackBlitz.
from = convert an array into an observable
The “from” method creates an observable from an array. e.g. from(array).
Try it out on StackBlitz.
interval = emit a value every second
The “interval” operator emits a value every second. e.g. interval(1000).
Try it out on StackBlitz.
fromEvent = capture an event e.g. a keypress
The “fromEvent” method creates an observable from an event. E.g. fromEvent(myInput, ‘keyup‘).
Try it out on StackBlitz.
Other articles in this series
- RxJS 6 examples in Angular 6 – Creating observables
- RxJS 6 examples in Angular 6 – Transformation Operators
- RxJS 6 examples in Angular 6 – Filtering Operators
- RxJS 6 examples in Angular 6 – Conditional Operators
- RxJS 6 examples in Angular 6 – Error Handling Operators
- RxJS 6 examples in Angular 6 – Unsubscribe from Observables