Sai
Sai

Reputation: 2658

Difference in importing Observable from 'rxjs/Observable' and 'rxjs'

I have created an observable using Observable.of() by importing it from rxjs/Observable. But, editor was showing error. But, after so many trials I changed it from rxjs/Observable to rxjs. Then it worked fine. May I know the difference between those. I have referred some solutions for the similar questions. But, they did not provide the complete solution. Please help me understand this.

Thanks..

Upvotes: 0

Views: 5731

Answers (2)

jme11
jme11

Reputation: 17374

When you import 'rxjs' you're importing the entire library. Because the library is large, this is not ideal. However, if you import Observable separately, you'll need to also include an import for 'of' separately, such as:

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';

EDIT For Angular 6:

import { Observable } from 'rxjs';
import { of } from 'rxjs';

Upvotes: 7

Shadab K
Shadab K

Reputation: 1755

In Angular 6 it works as

import { Observable } from 'rxjs';

Upvotes: 2

Related Questions