tried attempt 1: I made an effort to extract data using the function below. Due to its asynchronous nature, I encountered difficulty in retrieving the value from this function.
for (var i = 0; i < this.items.length; i++) {
let newitems: any = this.items;
this.restapi.getPendingOrdersCount(this.items[i].store._id, this.user._id).then(data => {
this.result = data;
console.log(this.result);
//able to get the data here
});
//Unable to fetch the data here.
newitems[i].pendingCount = this.result;
console.log("result", this.result);
}
attempt 2: I introduced an additional variable to the previous function and added a return statement. Now I am able to access this data but it appears as a zone value instead of the actual value => t {__zone_symbol__state: null, __zone_symbol__value: Array(0)}
let newitems: any = this.items;
for (var i = 0; i < this.items.length; i++) {
var response = this.restService.getPendingOrdersCount(this.items[i].store._id, this.user._id).then(data => {
this.result = data;
//console.log(this.result);
return response;
});
//able to access result here but it shows as a zone value
newitems[i].pendingCount = this.result;
console.log("response", response);
}
Seeking assistance in rectifying the above function for reusability of promise value.