angular - 在 Angular rxjs 服务中,如何从 HttpClient.get 的返回对象的属性中返回一个 observable
问题描述
在角度服务中,我希望该方法返回数据的属性而不是所有数据。
我试过这个:
export class RecipeService {
private recipesUrl = 'http://localhost:8081/recipes';
constructor(private http: HttpClient) { }
getRecipes (): Observable<Recipe[]> {
return this.http.get<Recipe[]>(this.recipesUrl).pipe((data) => {
return of(data['recipes']);
});
}
}
解决方案
你可以试试pluck运算符。
getRecipes (): Observable<Recipe[]> {
return this.http
.get<Recipe[]>(this.recipesUrl)
.pipe(pluck('recipes'));
}
推荐阅读
- database - PL/SQL ORA-29280: 无效的目录路径和 ORA-06512: 在 oracle 11g 中的“SYS.UTL_FILE”
- python - 如何在 Django 中添加默认不支持的语言?
- python - 如何检查是否在 tkinter 上单击了按钮
- c# - 将 String 转换为 String[] 但在撇号中不使用逗号
- r - ddply 和 group_by 的更快替代方案
- r - 带有 data.table 的每个自变量的线性回归循环
- css - 带有省略号的 CSS3 flexbox 布局在移动 Safari 上不起作用
- sql-server - SQL Server 2012 合并复制 - 全文索引
- mysql - django扩展查询条件`COLLATION`
- python - 如何在标注器之前/之后强制在 spacy 中使用 pos 标签?