• <tfoot id='3w5hq'></tfoot>

  • <legend id='3w5hq'><style id='3w5hq'><dir id='3w5hq'><q id='3w5hq'></q></dir></style></legend>

      • <bdo id='3w5hq'></bdo><ul id='3w5hq'></ul>

      <small id='3w5hq'></small><noframes id='3w5hq'>

        <i id='3w5hq'><tr id='3w5hq'><dt id='3w5hq'><q id='3w5hq'><span id='3w5hq'><b id='3w5hq'><form id='3w5hq'><ins id='3w5hq'></ins><ul id='3w5hq'></ul><sub id='3w5hq'></sub></form><legend id='3w5hq'></legend><bdo id='3w5hq'><pre id='3w5hq'><center id='3w5hq'></center></pre></bdo></b><th id='3w5hq'></th></span></q></dt></tr></i><div id='3w5hq'><tfoot id='3w5hq'></tfoot><dl id='3w5hq'><fieldset id='3w5hq'></fieldset></dl></div>

        Angular 2 HTTP 进度条

        时间:2023-09-08
            <tbody id='KuQz8'></tbody>

            <bdo id='KuQz8'></bdo><ul id='KuQz8'></ul>
            <legend id='KuQz8'><style id='KuQz8'><dir id='KuQz8'><q id='KuQz8'></q></dir></style></legend>

            <small id='KuQz8'></small><noframes id='KuQz8'>

          • <tfoot id='KuQz8'></tfoot>
            • <i id='KuQz8'><tr id='KuQz8'><dt id='KuQz8'><q id='KuQz8'><span id='KuQz8'><b id='KuQz8'><form id='KuQz8'><ins id='KuQz8'></ins><ul id='KuQz8'></ul><sub id='KuQz8'></sub></form><legend id='KuQz8'></legend><bdo id='KuQz8'><pre id='KuQz8'><center id='KuQz8'></center></pre></bdo></b><th id='KuQz8'></th></span></q></dt></tr></i><div id='KuQz8'><tfoot id='KuQz8'></tfoot><dl id='KuQz8'><fieldset id='KuQz8'></fieldset></dl></div>

                  本文介绍了Angular 2 HTTP 进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  目前在 Angular 2 中是否有一种方法可以使用 angular2/http 模块检索 ajax 调用的进度(即完成百分比)?

                  Is there currently a way within Angular 2 to retrieve the progress (i.e. percentage done) of an ajax call, using the angular2/http module?

                  我使用以下代码进行 HTTP 调用:

                  I use the following code to make my HTTP calls:

                          let body = JSON.stringify(params);
                          let headers = new Headers({ 'Content-Type': 'application/json' });
                          let options = new RequestOptions({ headers: headers });
                          this.http.post(url, body, options)
                              .timeout(10000, new Error('Timeout exceeded during login'))
                              .toPromise()
                              .then((res) => {
                                  ...
                              }).catch((err) => {
                                  ...
                              });
                  

                  目标是编写一个同步系统.帖子会返回大量数据,我想告诉用户同步需要多长时间.

                  The goal is to write a synchronisation system. The post will return a lot of data, and I want to give the user an indication on how long the syncing will take.

                  推荐答案

                  目前(从 v. 4.3.0 开始,当使用来自 @ngular/common/httpHttpClient 时>) Angular 提供开箱即用的监听进度.您只需要创建 HTTPRequest 对象,如下所示:

                  Currently (from v. 4.3.0, when using new HttpClient from @ngular/common/http) Angular provides listening to progress out of the box. You just need to create HTTPRequest object as below:

                  import { HttpRequest } from '@angular/common/http';
                  ...
                  
                  const req = new HttpRequest('POST', '/upload/file', file, {
                    reportProgress: true,
                  });
                  

                  当您订阅请求时,您将在每个进度事件中调用订阅:

                  And when you subscribe to to request you will get subscription called on every progress event:

                  http.request(req).subscribe(event => {
                    // Via this API, you get access to the raw event stream.
                    // Look for upload progress events.
                    if (event.type === HttpEventType.UploadProgress) {
                      // This is an upload progress event. Compute and show the % done:
                      const percentDone = Math.round(100 * event.loaded / event.total);
                      console.log(`File is ${percentDone}% uploaded.`);
                    } else if (event instanceof HttpResponse) {
                      console.log('File is completely uploaded!');
                    }
                  });
                  

                  更多信息这里.

                  这篇关于Angular 2 HTTP 进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:XPath 具有条件的多个属性值之一 下一篇:关闭应用程序时收听 Firebase 数据库更改

                  相关文章

                  最新文章

                  1. <small id='acKtE'></small><noframes id='acKtE'>

                  2. <tfoot id='acKtE'></tfoot>

                      • <bdo id='acKtE'></bdo><ul id='acKtE'></ul>
                      <legend id='acKtE'><style id='acKtE'><dir id='acKtE'><q id='acKtE'></q></dir></style></legend>
                    1. <i id='acKtE'><tr id='acKtE'><dt id='acKtE'><q id='acKtE'><span id='acKtE'><b id='acKtE'><form id='acKtE'><ins id='acKtE'></ins><ul id='acKtE'></ul><sub id='acKtE'></sub></form><legend id='acKtE'></legend><bdo id='acKtE'><pre id='acKtE'><center id='acKtE'></center></pre></bdo></b><th id='acKtE'></th></span></q></dt></tr></i><div id='acKtE'><tfoot id='acKtE'></tfoot><dl id='acKtE'><fieldset id='acKtE'></fieldset></dl></div>