import { Observable, of } from "rxjs";

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

我收到一个错误,声明类型"typeof Observable"上不存在属性"of"

推荐答案

看起来卡坦特的 comments 是正确的,RxJS upgrade guide没有特别提到那个方法,但确实说是"Classes that operate on observables have been replaced by functions"

这似乎意味着所有或大部分的类方法,比如.属于throw等已被函数替换

所以

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

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

Angular相关问答推荐

Angular v12:Uncatch(in promise):ReferenceError:d3 is not defined ReferenceError:d3 is not defined

如何跨不同组件使用ng模板

PrimeNG面包屑组件生成奇怪的&

MAT-复选框更改事件未在onSubscriberCheck函数中返回选中的值

使用jsPDF生成带有图像的PDF时出现灰色条纹

如何将Angular 服务包含在延迟加载的独立组件路由中?

是否可以在Angular(12+)中迭代指定的范围而不是整个数组

Angular 迁移 14 到 15 / 16:angular universal 是否停止将 <!-- this page was prerendered with angular universal --> 用于预渲染页面?

角 12 固态继电器 |页眉页脚在加载程序到来之前显示

如何禁用特定数据集图表js的默认标签

类型错误:无法读取未定义的属性

在 Ionic 2 中使用 NodeJS.Timer 时找不到命名空间 NodeJS

无法绑定到matDatepicker,因为它不是 input的已知属性

Angular 2 单元测试 - @ViewChild 未定义

如何提高 Angular2 应用程序的加载性能?

如何以编程方式触发`valueChanges`?

如何在 Angular 2 中动态添加和删除表单字段

包 '@angular/cli' 不是依赖项

找不到@angular/common/http模块

ngIf - 判断后表达式已更改