无法在RxJs 6和Angular 6中使用Observable.of [英] Could not use Observable.of in RxJs 6 and Angular 6

查看:130
本文介绍了无法在RxJs 6和Angular 6中使用Observable.of的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 import { Observable, of } from "rxjs";

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

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

I am getting an error stating, Property 'of' does not exist on type 'typeof Observable'

推荐答案

看起来像卡特的评论是正确的, RxJS升级指南没有具体介绍该方法,但确实说了对可观察对象进行操作的类已被函数替换"

Looks like cartant's comment is correct, the RxJS upgrade guide doesn't cover that method specifically but does say "Classes that operate on observables have been replaced by functions"

这似乎意味着.of,.throw等所有或大多数类方法已被函数替换

Which seems to mean all or most of those class methods like .of, .throw etc. have been replaced by a function

所以不是

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

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

这篇关于无法在RxJs 6和Angular 6中使用Observable.of的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆