我在https://angular.io岁时就开始学习教程了,但我很难找到文档;特别是对于方法pipetap.我在https://angular.iohttp://reactivex.io/rxjs/上找不到任何东西.

我的理解是pipetap都是Observable的方法,都是从RxJS导入的,对吗?他们该怎么办?

这些方法是Angular的一部分吗?这两种方法的作用是什么?

推荐答案

你说得对,文档中缺少这些方法.然而,当我深入研究rxjs存储库时,我发现了大约tap条(太长了,无法在这里粘贴)和pipe个操作员的好 comments :

  /**
   * Used to stitch together functional operators into a chain.
   * @method pipe
   * @return {Observable} the Observable result of all of the operators having
   * been called in the order they were passed in.
   *
   * @example
   *
   * import { map, filter, scan } from 'rxjs/operators';
   *
   * Rx.Observable.interval(1000)
   *   .pipe(
   *     filter(x => x % 2 === 0),
   *     map(x => x + x),
   *     scan((acc, x) => acc + x)
   *   )
   *   .subscribe(x => console.log(x))
   */

简而言之:

Pipe:用于将函数运算符拼接成链.以前我们只能做observable.filter().map().scan(),但是因 for each RxJS操作符都是一个独立的函数,而不是可观察对象的方法,所以我们需要pipe()来构建这些操作符的链(参见上面的示例).

Tap:可以对观察到的数据执行副作用,但does not modify可以以任何方式对流执行副作用.以前叫do().你可以把它想象成一个数组,随着时间的推移,tap()相当于Array.forEach().

Angular相关问答推荐

将kendo—colorpicker的kendo弹出窗口附加到组件''

如何在Angular中执行一个操作条件为多个可观测值?

带输入的单位测试Angular 分量.需要

如何将管道异步化添加到不在html模板中的观察对象的Angular ?

如何确保[共享]组件是真正的哑组件?(Angular )

列表和映射的SCSS语法

具有两个订阅方法的 Angular 16 takeUntilDestroyed 运算符

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

如何在 Angular14 中创建带有验证的自定义输入组件?

Angular:为什么在 ngAfterContentInit 之后变量未定义?

RxJS 基于先前的数据响应执行请求(涉及循环对象数组)

带有数据的 Angular 模板

如何在对话框angular material内对齐按钮?

如何在数据表angular material中显示空消息,如果未找到数据

Angular2 Material Dialog css,对话框大小

Angular2 SVG xlink:href

Angular 2:无法绑定到 x,因为它不是已知的本机属性

Angular 2 单元测试 - 出现错误无法加载ng:///DynamicTestModule/module.ngfactory.js

Angular2 - 从外部验证和提交表单

Angular 2:如何编写 for 循环,而不是 foreach 循环