angular - 为什么我的 httpclient 中的 rxjs 管道函数返回 Observable
问题描述
在这段代码中
getHero(id: number): Observable<Hero> {
const url = `${this.heroesUrl}/${id}`;
return this.http.get<Hero>(url).pipe(
tap(_ => this.log(`fetched hero id=${id}`)),
catchError(this.handleError<Hero>(`getHero id=${id}`))
);
}
从这里的Angular文档 工作正常,而在我的项目中,“相同”的代码给了我错误
错误 TS2322:类型“Observable”不可分配给类型“Observable”。
升级到 Angular 6 后?
public getCustomer(customerRecId: string): Observable<Customer> {
const url = `${this.baseUrl}/Customer?recId=${customerRecId}`;
const customer$ = this.http.get(url, this.httpOptions).pipe(
map(this.mapCustomer),
catchError(this.handleError)
);
return customer$;
}
将鼠标悬停在 vsCode 中的“.pipe”上显示在前一个示例中它返回一个 Observable 但在后者中返回一个 Observable
我不明白为什么这两个例子不同。
解决方案
推荐阅读
- c++ - 将文件上传到 S3 aws sdk cpp 时出错
- python - 如何为 ECS 任务定义创建日志记录?
- spring - 为什么轴突框架不能插入到自己的表中?
- javascript - 无法读取未定义的属性“id”
- node.js - 用于响应和表达受保护路由的 JSON webtoken 登录授权
- c# - 如何在 C#/.net 中将 XML 数据链接在一起
- python-3.x - 如何识别和计算矩形中的圆?
- github - 在同一个网站(Jekyll GitHub)上创建两个博客而不改变布局/格式
- excel - 如何使用 Excel VBA 单击 Web 复选框?
- facebook - 如何在没有访问令牌的组中发布帖子