angular - 导入 lettable operators 和 observable 创建方法

标签 angular typescript rxjs reactive-programming rxjs-lettable-operators

我正在升级到 Angular 5 和 RxJS 5.5.2 并尝试导入 Observable.of 运算符。

在lettable operators之前,我们是这样做的:

import 'rxjs/add/observable/of';

// Usage
Observable.of(...)

但现在不鼓励从包含 add 的路径导入。

那么现在引入和使用可让静态运算符的正确方法是什么?

最佳答案

现在具有可出租版本的运算符是实例运算符。

5.5.x of 和任何其他可观察的创建方法 可以静态方式使用,如下所示:

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

docs rxjs 对这个主题非常清楚:

You pull in any operator you need from one spot, under 'rxjs/operators' (plural!). It's also recommended to pull in the Observable creation methods you need directly as shown below with range:

import { range } from 'rxjs/observable/range';
import { map, filter, scan } from 'rxjs/operators';

const source$ = range(0, 10);

source$.pipe(
  filter(x => x % 2 === 0),
  map(x => x + x),
  scan((acc, x) => acc + x, 0)
)
.subscribe(x => console.log(x))

关于angular - 导入 lettable operators 和 observable 创建方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47189540/

相关文章:

c# - TypeScript 从不在 C# 中输入?

testing - 在生产模式下隐藏 angular2 组件的最佳解决方案?

javascript - 奇怪的函数参数

angular - RxJS 6 过滤并映射一个可观察的项目数组

angular - 选择选项不适用于 Angular 4 中的 ng-model

angular - 为什么我在 Angular 6 中的服务出现错误?

angular - iPad 的 Safari 10 无法加载 Angular 5 应用程序(适用于 Safari 11)

angular - angular2 中路由器和不推荐使用的路由器之间的区别

angular - 如何在 Angular 中使用 subscribe-next RxJS?

angular - TS7016 : Could not find a declaration file for module 'rxjs'