Angular教程中的管道和点按方法是什么?

Ben*_*bin 110 angular

我正在关注https://angular.io上的教程,但我找不到文档; 专门针对方法pipe和tap.我在https://angular.io或http://reactivex.io/rxjs/上找不到任何内容.

我的理解是,pipe和tap有两种方法Observable,它正在从RxJS进口,是否正确?他们该怎么办?

我应该在哪里寻找方法的文档?

Dan*_*cal 79

你是对的,文档缺乏这些方法.然而,当我挖掘到rxjs存储库时,我发现了关于tap(太长时间无法粘贴)和管道运算符的好评:

  /**
   * 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))
   */
Run Code Online (Sandbox Code Playgroud)

  • 从5.5开始引入可管理的(一度称为lettable)运算符,`do`被重命名为`tap` ...简而言之,它是一团糟.https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md (17认同)
  • 感谢您的回答和链接.我的部分问题是我是Angular的新手,我不确定哪些方法是核心JavaScript或Node.js或RxJS或Angular的一部分.你的回答帮助我澄清了这一点.谢谢. (3认同)
  • @BenRubin我建议您在开始学习工具之前先学习原生JS.它将使得理解工具及其实际操作变得更加容易(并且知道哪些部分是原生工具与工具相比). (3认同)
  • `filter`的工作方式与`Array.filter`类似-仅保留满足规则的值(在这种情况下,该值可以被2整除);map(再次类似于Array.map)会更改每个值(在这种情况下,将其添加到自身);扫描是最有趣的,这是一个很好的解释:https://www.learnrxjs.io/operators/transformation/scan.html (2认同)