angular - 另一个角度内的http请求
问题描述
我正在从数据库中获取食谱(在效果中 - 请参见下面的代码),其中每个食谱都有成分。下面是对应的Recipe模型代码:
export class Recipe {
id_recipe: number;
name: string;
image: string;
difficulty: number;
category_id: number;
country_id: number;
ingredients: Ingredient[];
}
这是我的角度代码
@Effect()
fetchRecipes = this.actions$.pipe(
ofType(RecipesActions.FETCH_RECIPES),
switchMap(() => {
return this.http.get<Recipe[]>('http://localhost/recipes/get.php',
{
params: new HttpParams().set('q', 'SELECT * FROM recipe')
})
}),
map(recipes => {
return recipes.map(recipe => {
return {
...recipe,
ingredients: this.http.get<Ingredient[]>('http://localhost/recipes/get.php',
{
params: new HttpParams().set('q', 'SELECT name, amount, units FROM ingredient INNER JOIN recipe_has_ingredient ON ingredient.id_ingredient = recipe_has_ingredient.id_ingredient WHERE recipe_has_ingredient.id_recipe = ' + recipe.id_recipe)
})
}
})
}),
map(recipes => {
return new RecipesActions.SetRecipes(recipes);
})
);
我想根据配方 ID 获取配料。目前我将成分作为可观察的,但我想要一个数组。有人可以帮我吗?
解决方案
推荐阅读
- javascript - 根据窗口大小更改道具值
- ajax - Laravel Ajax“GET”不断导致500错误
- java - NoClassDefFoundError: org/bouncycastle/openssl/PEMParser 在 Jenkins 上使用 SSHJ 时
- html - SVG clipPath 没有正确裁剪
- python - 如何从 asn1 数据文件中提取数据并将其加载到数据框中?
- r - R 难以识别带有 [:...:] 的正则表达式
- laravel - Laravel 中的更新方法
- javascript - 图像资源由 Electron-Builder 重命名
- firebase - 当用户在flutter中使用otp方法登录时,如何检查用户详细信息是否已经存在于firebase中?
- ruby-on-rails - 如何不按 N 值数量而是按 created_at.day 对记录进行分页?