什么是Angular中的pipe()函数 [英] What is pipe() function in Angular
问题描述
管道是用于转换模板中数据(格式)的过滤器.
Pipes are filters for transforming data (formats) in the template.
我遇到了pipe()
函数,如下所示.在这种情况下,此pipe()
函数的确切含义是什么?
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}`))
);
推荐答案
不要与Angular和RxJS的概念混淆
Don't get confused with the concepts of Angular and RxJS
我们在Angular中具有管道概念,在RxJS中具有pipe()
函数.
We have pipes concept in Angular and pipe()
function in RxJS.
1)角度管道:管道将数据作为输入并将其转换为所需的输出
https://angular.io/guide/pipes
1) Pipes in Angular: A pipe takes in data as input and transforms it to the desired output
https://angular.io/guide/pipes
2)RxJS中的 pipe()
函数:您可以使用管道将运算符链接在一起.管道使您可以将多个功能组合为一个功能.
2) pipe()
function in RxJS: You can use pipes to link operators together. Pipes let you combine multiple functions into a single function.
pipe()
函数将要组合的函数作为其参数,并返回一个新函数,该函数在执行时将依次运行组成的函数.
https://angular.io/guide/rx-library (在此URL中搜索管道,您可以找到相同的内容)
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)
因此,根据您的问题,您指的是RxJS中的pipe()
函数
So according to your question, you are referring pipe()
function in RxJS
这篇关于什么是Angular中的pipe()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!