I have the following code:
forkJoin([
this.restangular.all(this.commonService.getHospitalURI()).getList(),
this.restangular.all(this.commonService.getAgeGroupURI()).getList()
]).subscribe(responses => {
const hospital_result = responses[0];
// Error because of the line below
const agegroup_result = Array.from(responses[1]);
console.log('hospital ' + JSON.stringify(hospital_result))
console.log('agegroup ' + JSON.stringify(agegroup_result))
for (const productID_hospital of hospital_result[0]['product']) {
for (const productID_agegroup of agegroup_result) {
// Do Something here
}
}
})
I'm using Angular 5, doing a forkjoin to call a response sequentially. This part is completely fine. But the error comes when it is trying to parse the JSON.
I get this error:
src/app/layout/insurance-list/insurance-list.component.ts(75,48): error TS2345: Argument of type '{}' is not assignable to parameter of type 'Iterable<{}>'.
Property '[Symbol.iterator]' is missing in type '{}'.
If I change
const agegroup_result = Array.from(responses[1]);
to
const agegroup_result = responses[1];
Then I'll get an error:
src/app/layout/insurance-list/insurance-list.component.ts(85,50): error TS2495: Type '{}' is not an array type or a string type.
I don't understand why I am having this error. I am parsing the JSON correctly as it returns an array first. I am unable to run my project due to this error.
Edit:
Here is the link to the JSON for agegroup_result: https://plnkr.co/edit/hzkPXqWfGmNNgHuHwAzT?p=catalogue
It's named as agegroup.json
Edit 2:
console.log(responses[1] instanceof Array)
The above code returns true. Response[1] is an Array.