无法在 RxJs 6 和 Angular 6 中使用 Observable.of

Could not use Observable.of in RxJs 6 and Angular 6

 import { Observable, of } from "rxjs";

// And if I try to return like this
  return Observable.of(this.purposes);

我收到一条错误消息,指出 属性 'of' 在类型 'typeof Observable'

上不存在

看起来 cartant 的评论是正确的,RxJS upgrade guide 没有具体涵盖该方法,但确实说 "Classes that operate on observables have been replaced by functions"

这似乎意味着所有或大部分 class 方法,如 .of、.throw 等已被函数取代

所以不用

import { Observable, of } from "rxjs";
Observable.of(this.purposes);

import { of } from "rxjs";
of(this.purposes);

rxjs 6

import { PreloadingStrategy, Route } from '@angular/router';
import { Observable, of } from 'rxjs';

export class SelectivePreloadingStrategy implements PreloadingStrategy {
    preload(route: Route, load: Function): Observable<any> {
       return route.data && route.data.preload === false ? of(null) : load();
    }

 }

为了避免 ,像这样导入它们:

import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';