import { Observable, of } from "rxjs";
// And if I try to return like this
return Observable.of(this.purposes);
我收到一条错误消息,指出“typeof Observable”类型上不存在属性“of”
import { Observable, of } from "rxjs";
// And if I try to return like this
return Observable.of(this.purposes);
我收到一条错误消息,指出“typeof Observable”类型上不存在属性“of”
看起来 carant 的评论是正确的,RxJS 升级指南没有具体介绍该方法,但确实说“对可观察对象进行操作的类已被函数替换”
这似乎意味着所有或大部分类方法(如 .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();
}
}
为避免rxjs 被列入黑名单,请像这样导入它们:
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';