I am having issue with importing Observable.of
function in my project. My Intellij sees everything. In my code I have:
import {Observable} from
For me (Angular 5 & RxJS 5) the autocomplete import suggested:
import { Observable } from '../../../../../node_modules/rxjs/Observable';
while to should be (with all static operators from
, of
, e.c.t working fine:
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
shows a requirement of rxjs-compat
require("rxjs-compat/add/observable/of");
I did not have this installed. Installed by
npm install rxjs-compat --save-dev
and rerunning fixed my issue.
If anybody is having this problem while using Angular 6/rxjs 6 see the answers here: Could not use Observable.of in RxJs 6 and Angular 6
In short, you need to import it like this:
import { of } from 'rxjs';
And then instead of calling
Observable.of(res);
just use
of(res);
You could also import all operators this way:
import {Observable} from 'rxjs/Rx';
If you are using Angular 6 /7
import { of } from 'rxjs';
And then instead of calling
Observable.of(res);
just use
of(res);
For Angular 5+ :
import { Observable } from 'rxjs/Observable';
should work. The observer package should match the import as well import { Observer } from 'rxjs/Observer';
if you're using observers that is
import {<something>} from 'rxjs';
does a huge import so it's better to avoid it.