4

What is the best way to display a progress bar in an Angular2 application when an HTTP request is being carried out?

I tried the following using AngularMaterial2 progress bar:

<md-progress-bar mode="determinate" value="myValue"></md-progress-bar>

But how to find the 'value' for the above code?

(If it is not possible to find out the actual progress of an HTTP request, what is the best way to achieve a Youtube or Github style progress bar?)

Frederik Struck-Schøning
  • 12,981
  • 8
  • 59
  • 68
duke636
  • 742
  • 2
  • 6
  • 12

2 Answers2

0

We can not determine the time required to complete the HTTP request that's why indeterminate mode is more suitable for the progress of HTTP requests.

Angular's Http service returns an Observable to which we can subscribe and handle the response, right now there is no mechanism available to get progress from Http service.

One way is to use XmlHttpRequest to listen for the progress event and if the use its lengthComputable property and can show progress bar accordingly.

so one way to achieve a Youtube or Github style progress bar has been shown in this answer.

If you have more than one request, you could use the number of completed requests as a percentage.

Community
  • 1
  • 1
HirenParekh
  • 3,655
  • 3
  • 24
  • 36
-3

Use library, module, or packages from public source code widely available in internet

Here are some Angular 2 examples:

  1. https://embed.plnkr.co/rx4RJUFjHqGYMA3jRxDL/

  2. http://www.angulartypescript.com/angular-2-progress-bar/