I have some question about rxjs function. Actually, I make a request to http server. The way I receive data from http server is two steps because each request returns only 10 items, not entire items. Each request has page number so, if I have a total number of 100 items, I have to make quest 10 times. So, before making request one by one, I extract the total number of pages first, then I loop through request as many as the number of pages. In order to do it, I use switchMap function like below.
getItems(id: string) {
return this.dataService.getPageNum(id).switchMap (
(page_num: number) => {
for(let i=1; i<=page_num; i++) {
this.dataService.getItems(id, i).subscribe(
(data: Object) => {
this.items.push(data);
}
)
}
}
);
}
It returns error error TS2345: Argument of type '(page_num: number) => void' is not assignable to parameter of type '(value: number, index: number) => ObservableInput<{}>'. Type 'void' is not assignable to type 'ObservableInput<{}>'.
So, I searched some information regarding this issue, I found something,
Angular 2 - RxJS Switch Map Issue
but I do not understand what question and answer says well. That means I should put Observable.empty() to make it work? Also, I even tried to return Observable.of(null) and Observable.empty(), it says that Property 'empty' does not exist on type 'typeof Observable' even I imported that function.