[Angular] Progress HTTP Events with 'HttpRequest'

New use case that is supported by the HTTP client is Progress events. To receive these events, we create our HTTP request manually in the following way:

longRequest() {

    const request = new HttpRequest(
        "POST", "/api/test-request", {}, 
         {reportProgress: true});

    this.http.request(request)
        .subscribe(
            event => {

                if (event.type === HttpEventType.DownloadProgress) {
                    console.log("Download progress event", event);
                }

                if (event.type === HttpEventType.UploadProgress) {
                    console.log("Upload progress event", event);
                }

                if (event.type === HttpEventType.Response) {
                    console.log("response received...", event.body);
                }

            }
        );
}

 

HttpEventType can be found here: link

posted @ 2017-08-23 16:14  Zhentiw  阅读(555)  评论(0编辑  收藏  举报