Currently, I've been attempting to connect the onCompleteItem
array function from the ng2-file-upload
package with an RxJS Observable method that can be subscribed to.
The function in question looks like this:
onCompleteItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any;
..which essentially is similar to:
onCompleteItem(item: any, response: any, status: any, headers: any)
Below are the important sections from MyComponent, where everything is currently functioning smoothly:
imageArray: Image[] = [];
uploader:FileUploader = new FileUploader({
url: '/api/FileUpload'
});
ngOnInit() {
this.uploader.onCompleteItem = (item: any, response: any, status: any, headers: any) => {
const data = JSON.parse(response);
data.forEach(x => {
console.log(x);
this.imageArray.push(x);
}
this.uploader.removeFromQueue(item);
};
}
I made an effort to bind this as an Observable using the RxJS bindCallback
function:
bindCallback(this.uploader.onCompleteItem, {item: any, response: any, status: any, headers: any})().pipe(
tap((item, response) => {
const data = JSON.parse(response);
this.uploader.removeFromQueue(item);
const images = data.map(x => console.log(x) );
this.imageArray.push(...images);
})
).subscribe();
Unfortunately, this approach encounters some type and syntax errors. Any suggestions on a better way to rewrite this as a bound Observable function?