Reputation: 99
I'm trying to have an array of categories that contains item but without no luck. This is the code:
public getItemsAndSubcategoriesFromCatAndCategory(catalogue_key: string, category_key: string): Observable<any> {
return this.categoriesService.getSubCategories(catalogue_key, category_key)
.combineAll()
.switchMap((val) => {
const obj = {};
this.getItemsInSubcategory(catalogue_key, val[0].key).map((items) => {
obj[val[0].key] = items;
});
return obj;
});
}
the error is:
Argument of type (val: {}) => {} is not assignable to parameter of type (value: {}, index: number) => ObservableInput<{}>
any Idea?
Upvotes: 0
Views: 496
Reputation: 136
.switchMap
needs Observable
to be returned instead of {}
.
So use
return Observable.of(obj)
instead of
return obj
EDIT:
You can write in more declarative syntax:
.switchMap(([firstValue]) => Observable.of(
this.getItemsInSubcategory(catalogue_key, firstValue.key)
.reduce((obj, items) => Object.assign({}, obj, {
[firstValue.key]: items
}, {})
))
Upvotes: 0