gpt4 book ai didi

angular - 你怎么用 pipe 接住?

转载 作者:太空狗 更新时间:2023-10-29 17:17:43 25 4
gpt4 key购买 nike

如何使用可出租运算符和管道执行以下操作?

    this.httpClient
.get(url)
.map((res: any) => {
const events = res.eventList;
return events.map(e => new EventLogModel(e));
})
.catch(this.handleError);

我已经试过了,但我无法得到 catchError上类:catchError does not exist on type Observable<any> :

    this.httpClient
.get(url)
.pipe(
map((res: any) => {
const events = res.eventList;
return events.map(e => new EventLogModel(e));
})
)
.catchError(this.handleError);

此外,我假设 catchcatchError是一样的,对吗?我像这样导入它:

import { map, catchError } from 'rxjs/operators';

但我不确定这是否是正确的运算符。

最佳答案

你的假设是正确的,lettable 运算符catchErrorcatch 相同。

关于catchError的放置,不应该有前缀.,应该放在pipe中:

this.httpClient
.get(url)
.pipe(
map((res: any) => {
const events = res.eventList;
return events.map(e => new EventLogModel(e));
}),
catchError(this.handleError);
)

关于angular - 你怎么用 pipe 接住?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47600201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com