I am trying to return value to this.voucherDetails using subscribe but it doesn't seem to work.
Following is the request to the function getVoucherDetails which has the subscribe function.
voucherIDs: string[];
voucherDetails: Promise<any>[];
this.voucherIDs = ['JV-2005-50','JV-2005-40','JV-2005-30'];
this.voucherDetails = this.voucherIDs
.map(id => this.getVoucherDetails(id));
Promise.all(this.voucherDetails)
.then(() => this.printService.onDataReady());
Following is the function with subscribe to userService which gets data from database.
getVoucherDetails(voucherid) {
var splitvoucher = voucherid.split('-');
var vouchertype = splitvoucher[0];
var vouchermy = splitvoucher[1];
var voucherno = splitvoucher[2];
var vouchernotopass = vouchermy+"-"+voucherno;
var voucherdate;
var enteries;
this.userService.getVoucher(vouchernotopass,vouchertype).subscribe(
res => {
voucherdate = res['voucherdate'];
enteries = res['enteries'];
return { "vouchertype":vouchertype, "vouchernumber": vouchernotopass, "voucherdate": voucherdate, "enteries":enteries};
}
);
}
But it returns undefined. After going through several posts I have come to understand that you can't return from a .subscribe. But I haven't been able to understand a work around on how to resolve this issue.