添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm following the tutorial at https://angular.io , and I'm having trouble finding documentation; specifically for the methods pipe and tap . I can't find anything on https://angular.io or http://reactivex.io/rxjs/ .

My understanding is that pipe and tap are both methods of Observable , which is being imported from RxJS, correct? What are they supposed to do?

Are these methods part of Angular? What do these two methods do?

I find it strange when users ask proper questions, receive a proper answer, and yet for the mods are clueless what OP is asking :D - why the hell is this "off-topic"? Paul Strupeikis Jan 29, 2019 at 14:49

You are right, the documentation lacks of those methods. However when I dug into rxjs repository, I found nice comments about tap (too long to paste here) and pipe operators:

* 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))

In brief:

Pipe : Used to stitch together functional operators into a chain. Before we could just do observable.filter().map().scan() , but since every RxJS operator is a standalone function rather than an Observable's method, we need pipe() to make a chain of those operators (see example above).

Tap : Can perform side effects with observed data but does not modify the stream in any way. Formerly called do() . You can think of it as if observable was an array over time, then tap() would be an equivalent to Array.forEach() .

Thank you for the answer and the links. Part of my problem is that I'm new to Angular, and I'm not sure which methods are part of core JavaScript or Node.js or RxJS or Angular. Your answer helped me to clarify that. Thank you. Ben Rubin Nov 14, 2017 at 0:57 @BenRubin I would recommend that you start by learning native JS properly before starting to learn the tools. It will make it much easier to understand the tools and what it actually does (and to know what parts is native vs the tool). M. Eriksson Nov 14, 2017 at 6:44 since 5.5 and the introduction of pipeable (once known as lettable) operators, do as been renamed as tap ... In short, it's a mess. github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md Luca Mar 12, 2018 at 14:22 filter works just like Array.filter - keeps only values fulfilling the rule (in this case divisible by 2); map (again like Array.map ) changes every value (in this case adds it to itself); scan is most interesting and here is a nice explanation: learnrxjs.io/operators/transformation/scan.html Daniel Kucal Aug 17, 2018 at 8:18

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .