Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular Rxjs 6相当于Observable.create(订户->;{…}).share()_Angular_Typescript_Rxjs_Observable_Rxjs6 - Fatal编程技术网

Angular Rxjs 6相当于Observable.create(订户->;{…}).share()

Angular Rxjs 6相当于Observable.create(订户->;{…}).share(),angular,typescript,rxjs,observable,rxjs6,Angular,Typescript,Rxjs,Observable,Rxjs6,我正在将Angular 5应用程序升级到Angular 6,因此从rxjs 5升级到rxjs 6,在迁移以下代码时遇到了问题: const myObservable = Observable.create(subscriber => { // do something with the subscriber }).share(); 特别是我得到了这个错误: TypeError:Observable_1.Observable.create(…)。共享不是一个 functionTyp

我正在将Angular 5应用程序升级到Angular 6,因此从rxjs 5升级到rxjs 6,在迁移以下代码时遇到了问题:

const myObservable = Observable.create(subscriber => {
    // do something with the subscriber
}).share();
特别是我得到了这个错误:

TypeError:Observable_1.Observable.create(…)。共享不是一个 functionTypeError:Observable_1.Observable.create(…)。共享不可用

上面的代码应该可以做到这一点

您需要按如下方式管道共享(),而不是链接:

const myObservable = Observable.create(subscriber => {
    // do something with the subscriber
}).pipe(share());
另外,请确保按如下方式导入共享:

import {share} from 'rxjs/operators';
import {share} from 'rxjs/operators';