10

I'm upgrading my Angular 5 app to Angular 6 and consequently from rxjs 5 to rxjs 6, I'm experiencing troubles in migrating the following piece of code:

const myObservable = Observable.create(subscriber => {
    // do something with the subscriber
}).share();

in particular I'm getting this error:

TypeError: Observable_1.Observable.create(...).share is not a functionTypeError: Observable_1.Observable.create(...).share is not

Francesco Borzi
  • 56,083
  • 47
  • 179
  • 252

2 Answers2

12

You need to pipe share() as follows instead of chaining:

const myObservable = Observable.create(subscriber => {
    // do something with the subscriber
}).pipe(share());

Also make sure you import share as follows:

import {share} from 'rxjs/operators';
siva636
  • 16,109
  • 23
  • 97
  • 135
3
import { Observable } from "rxjs";
...
let obs$ = new Observable(...);
...

Above code should do the trick

Abinesh Devadas
  • 1,517
  • 13
  • 15