I have an array of observables. Each observable is a file which needs to be uploaded via HTTP request.
I want to do two things:
- For each uploaded file I have to emit event which will be handled in parent component.
- When all files are uploaded I have return notify that all observable are completed.
I started with this code:
this.isUploading$ = Observable.of(true);
const source$ = Observable.from(files)
.concatMap(file => this.uploadSingleFile(file));
source$.subscribe(data => this.onSuccess.emit(data));
Observable isUploading$ represent that upload process started and it is consumed in HTML. I want to display spinner based on the state of isUploading$.
Observable source$ represents file uploads operations because method this.uploadSingleFile(file) with return Observable<Response>.
This code will upload all files and execute this.onSuccess.emit(data) on each completed observable.
The question is: How I can set this.isUploading$ to false when everything is done?
UPDATE:
I would like to achieve something like this but without assigning variable in onCompleted function. Example:
source$.subscribe(data => this.onSuccess.emit(data),
err => console.log(err),
() => this.isUploading = false );
I want to retrieve two observables and subscribe to them later whenever I want.