'Two functions that subscribe to the server api, executed in sequence
I have a question - it may seem obvious to you, but I can't figure it out.
getCategoryID() and getRecipeList()
The first one gets from the API a list of the category array, the second function uses this list to send (n = array length) requests regarding the recipes.
At the end, I want a array: category name + recipe name
The problem is that both use subscribe. Due to the fact that they are asynchronous, functions execute too quickly. Tried using await - but then it returns me a Promise. I want the first function to wait for the api to api query and pass the data to the second, not the promise
getCategoriesFromAPI() {
this.apiService.getCategories().subscribe(data => {
console.log(data);
});
}
getRecipesFromAPI() {
this.apiService.getRecipes(categoryID).subscribe(data => {
console.log(data);
});
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
