What is Observable in angular 6

If our angular application require communication between components  and asynchronous data from server then here are way to achieve that.

The way to communicate between components is to use an Observable and a Subject. But in this document am not describing Subject.

Observable belongs to RxJS library. To perform asynchronous programming in Angular application we can use either Observable or Promise. When we send and receive data over HTTP request. we need to deal it asynchronously because fetching data over HTTP may take time. Observable is subscribed by using async pipe or by using subscribe method.

Observable is a class of RxJS library. RxJS is ReactiveX library for JavaScript that performs reactive programming. Observable represents any set of values over any amount of time. Observable plays most basic role in reactive programming with RxJS. Some methods of Observable class are subscribe, map, mergeMap, switchMap, exhaustMap, debounceTime, of, retry, catch, throw etc.

To use RxJS library in Angular programming we need to ensure that we have installed RxJS. In case we are using Angular CLI, it installs RxJS by default. We can ensure it by checking package.json. If RxJS is not there in package.json, we can install it as following.

npm install rxjs --save

To use Observable in our Angular application, we need to import it as following.

import { Observable } from 'rxjs/Observable';


What is Observable in angular 6
Show Buttons
Hide Buttons