I have an item to work with:
let DataObject = {
'item1' : './someitem1.json',
'item2' : './someitem2.json',..
};
I want to fetch all items using RxJS and notify the subscriber only after all items have been fetched. Additionally, I want the subscriber to receive a result object with the original keys. For example:
let result = {
'item1' : fetchedData1,
'item2' : fetchedData2,..
}
The code snippet that I currently have is as follows:
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/forkJoin';
import 'rxjs/add/operator/concatAll';
import 'rxjs/add/observable/of';
let observableBatch = [];
for (let key in DataObject) {
observableBatch.push(
this.http.get(DataObject[key]).map(
(res) => {
return Observable.of({[key] : res.json()})
}
)
)
}
let mergedObs =Observable.forkJoin(observableBatch).concatAll();
mergedObs.subscribe((res) => {
console.log(res);
});
However, I am encountering an error stating "Property 'subscribe' does not exist on type '{}[]'."
How can I resolve this error? Is there a more concise way to achieve the same functionality?