What is pipe() function in Angular

Dinesh Sharma picture Dinesh Sharma · Dec 30, 2017 · Viewed 125.3k times · Source

Pipes are filters for transforming data (formats) in the template.

I came across the pipe() function as below. What does this pipe() function exactly mean in this case?

return this.http.get<Hero>(url)
  .pipe(
    tap(_ => this.log(`fetched hero id=${id}`)),
    catchError(this.handleError<Hero>(`getHero id=${id}`))
);

Answer

Shiva Nayak Dharavath picture Shiva Nayak Dharavath · Jul 3, 2018

Don't get confused with the concepts of Angular and RxJS

We have pipes concept in Angular and pipe() function in RxJS.

1) Pipes in Angular: A pipe takes in data as input and transforms it to the desired output
https://angular.io/guide/pipes

2) pipe() function in RxJS: You can use pipes to link operators together. Pipes let you combine multiple functions into a single function.

The pipe() function takes as its arguments the functions you want to combine, and returns a new function that, when executed, runs the composed functions in sequence.
https://angular.io/guide/rx-library (search for pipes in this URL, you can find the same)

So according to your question, you are referring pipe() function in RxJS