I'm using a forkJoin
of observables but I'm having troubles to pass arguments in my observables. Lines of code worth a thousand words:
for(var key in pdfObjects){
let pdf = {pdfObjects[key]};
observables.push(new Observable(observer => {
this.createPDF(pdf).subscribe((pdfFile) => {
// Do something with my pdfFile
observer.complete();
})
})
}
Observable.forkJoin(observables).subscribe(
(next) => {},
(error) => {},
(completed) => {
console.log('completed');
}
);
(I have simplified the code for better clarity)
As you can see here, the problem is that when the code executes the observables, the pdf
variable is equal to the last pdfObjects
instead of being a different variable for each observable.
The question is how can I 'pass' and 'copy' my pdf
variable so it's a diffent one for each observable?