import { Observable, of } from "rxjs";
// And if I try to return like this
return Observable.of(this.purposes);
我收到一条错误声明,“属性''在类型'上不存在'typeof Observable'
答案 0 :(得分:95)
看起来cartant的评论是正确的,RxJS upgrade guide没有特别涵盖该方法,但确实说“对可观察对象进行操作的类已被函数替换”
这似乎意味着所有或大多数类方法,如.of,.throw等已被函数替换
所以而不是
import { Observable, of } from "rxjs";
Observable.of(this.purposes);
DO
import { of } from "rxjs";
of(this.purposes);
答案 1 :(得分:3)
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();
}
}
答案 2 :(得分:0)
为避免使用black-list linting of the rxjs,请像这样导入它们:
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';