Created
December 6, 2018 15:46
-
-
Save YonathanMeguira/babbc0d239177ad0238da37ef2c3bec9 to your computer and use it in GitHub Desktop.
watch progress download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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