RxJS operator that extracts upload/download progress from an HttpEvent stream and reports it to a ManualAsyncState
tapAsyncProgress
Functioncommon/data/async-state
projects/common/data/async-state/operators.ts
Description#
RxJS operator that extracts upload/download progress from an
HttpEvent stream and reports it to a ManualAsyncState.
Filters progress events, calculates percentage, calls setProgress().
Non-progress events pass through unchanged.
Use with { observe: 'events', reportProgress: true } on HttpClient.
readonly upload = createManualState<UploadResult>();
handleUpload(file: File): void {
this.http.post('/api/upload', file, {
reportProgress: true,
observe: 'events',
}).pipe(
tapAsyncProgress(this.upload),
takeUntilDestroyed(this.destroyRef),
).subscribe();
}