Skip to content

Instantly share code, notes, and snippets.

@YonathanMeguira
Created December 6, 2018 15:46
Show Gist options
  • Save YonathanMeguira/babbc0d239177ad0238da37ef2c3bec9 to your computer and use it in GitHub Desktop.
Save YonathanMeguira/babbc0d239177ad0238da37ef2c3bec9 to your computer and use it in GitHub Desktop.
watch progress download
import { HttpEventType, HttpClient, HttpRequest, HttpEvent } from '@angular/common/http';
constructor(private http: HttpClient) {}
this.http.get(someUrl).subscribe((event: HttpEvent) => {
if (event.type === HttpEventType.DownloadProgress) {
const totalLoaded = event.loaded;
const totalToLoad = event.total;
// here is the ratio
const ratio = 100 / totalToLoad * totalLoaded;
}
// you have finished
if (event.type === HttpEventType.Response) {
console.log('done');
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment