Rxjs 6 相当于 Observable.create(subscriber -> {...}).share()
Rxjs 6 equivalent of Observable.create(subscriber -> {...}).share()
我正在将我的 Angular 5 应用程序升级到 Angular 6,因此从 rxjs 5 升级到 rxjs 6,我在迁移以下代码时遇到了问题:
const myObservable = Observable.create(subscriber => {
// do something with the subscriber
}).share();
特别是我遇到了这个错误:
TypeError: Observable_1.Observable.create(...).share is not a
functionTypeError: Observable_1.Observable.create(...).share is not
import { Observable } from "rxjs";
...
let obs$ = new Observable(...);
...
上面的代码应该可以解决问题
您需要按如下方式传递 share() 而不是链接:
const myObservable = Observable.create(subscriber => {
// do something with the subscriber
}).pipe(share());
还要确保按如下方式导入共享:
import {share} from 'rxjs/operators';
我正在将我的 Angular 5 应用程序升级到 Angular 6,因此从 rxjs 5 升级到 rxjs 6,我在迁移以下代码时遇到了问题:
const myObservable = Observable.create(subscriber => {
// do something with the subscriber
}).share();
特别是我遇到了这个错误:
TypeError: Observable_1.Observable.create(...).share is not a functionTypeError: Observable_1.Observable.create(...).share is not
import { Observable } from "rxjs";
...
let obs$ = new Observable(...);
...
上面的代码应该可以解决问题
您需要按如下方式传递 share() 而不是链接:
const myObservable = Observable.create(subscriber => {
// do something with the subscriber
}).pipe(share());
还要确保按如下方式导入共享:
import {share} from 'rxjs/operators';