I am consuming a WEB API endpoint that returns product data. However, upon subscribing, I want to assign variables to this data to be used as part of a bar chart generated using Chart.js (Not relevant).
The data that is returned can be seen as follows:
What I have tried is the following:
generateReport() {
if(this.service.reportForm.valid) {
this.service.getData().subscribe
(res => {
console.log(res)
let productNames = res['reportData'].map(res => res.ProductName);
let avgQuantityOrdereed = res['reportData'].map(res => res.AverageQuantityOrdered);
let orderQuantity = res['reportData'].map(res => res.ProductOrders.orderQuantity)
})
}
}
However, I get the error: "Element implicitly has an 'any' type because expression of type '"reportData"' can't be used to index type 'Object'" under the "res['reportData'].
Is there any alternative way to doing what i tried above? And also, what is wrong with the way i did it?
