In a calling method, I need to extract an array of categories (Category[]) from the returned value of this method. How do I do this. I am not up to speed on promises.
getCategories() : Promise<Category[]> {
return this.http.get(this.categoriesUrl).toPromise()
.then(response => response.json().data as Category[])
.catch(this.handleError);
}
And how do I extract a specific category from the result of the above getCategories() method? This is not working.
getCategory(id: string): Category {
return this.getCategories()
.filter((category: Category, index: number, array: Category[]) => {
return category.id === id;
});
}