什么是 Angular 中的 pipe() 函数 [英] What is pipe() function in Angular

查看:40
本文介绍了什么是 Angular 中的 pipe() 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

管道是用于转换模板中数据(格式)的过滤器.

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) Angular 中的管道:管道将数据作为输入并将其转换为所需的输出
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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆