I have been attempting to use subscribe to return a value to this.voucherDetails, but unfortunately, it doesn't seem to be working as expected.
Below is the code snippet for the getVoucherDetails function which includes the subscribe method.
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());
Here is the function that uses subscribe to userService to fetch data from the 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};
}
);
}
However, the function currently returns undefined. Through my research, I have learned that you cannot directly return from a .subscribe method. I am still trying to figure out a solution to this issue.