Rachid O
Rachid O

Reputation: 14012

Difference between `of` operator and `Observable.of`

So what is the difference between of operator and Observable.of and what is the recommended way to create an observable?

import { Observable } from 'rxjs/Observable';
const obs$ = Observable.of(3);

or

import { of as observableOf } from 'rxjs';
const obs$ = observableOf(3);

Upvotes: 3

Views: 5677

Answers (1)

The second way is the preferred way, and going forward (from rxjs v7) the only way. Currenly in v6 you can still use the first by including the rxjs-compat package, but writing new code, you should stick to the last method mentioned.

Upvotes: 6

Related Questions