I am making a server call this.recipeService.getAllRecipesByUserId() which returns a promise of type Recipe[]. I then resolve the promise using then and the allRecipes' array is populated with the correct data. The issue is that outside of the resolve scope, this.allRecipes[0]` is undefined.
ngOnInit(): void {
this.recipeService
.getAllRecipesByUserId()
.then((recipes) => (this.allRecipes = recipes));
this.recipe = this.allRecipes[0];
}
Am I missing something simple here or how should I assign data to a variable from the resolved promise ?