简体   繁体   English

使用Angular.js查找正在进行的http get请求的下载状态

[英]Find the download status of an http get request in progress using Angular.js

I've searched all over the web and can't seem to find anything that says, one way or the other, whether or not I can get the status of downloading data during an $http.get request. 我在网上搜索过,似乎无法找到任何说法,无论是否能在$http.get请求中获取下载数据的状态。 The application I'm writing regularly downloads a lot of data which can take up to 30 seconds. 我正在编写的应用程序会下载大量数据,这可能需要30秒。 Rather than display an animated loading gif, I would like to display a progress bar which shows the status of how much of the data has downloaded. 我想显示一个进度条,显示已下载了多少数据的状态,而不是显示动画加载gif。 I am using Angular.js and this is what my get request looks like. 我正在使用Angular.js,这就是我的get请求。

$http.get(<apiURL>).success(function(data,status,headers,config){
    $scope.data = data;
});

On the success of the request I populate my page with the data. 在请求成功的时候,我用数据填充了我的页面。 Is there some way to, in the time it's fetching that data from the server, to constantly read the download status? 在从服务器获取数据时,是否有某种方法可以不断读取下载状态?

I found a fantastic library to use in order to achieve what I wanted without having to change the back-end server code. 我发现了一个很棒的库,可以实现我想要的,而无需更改后端服务器代码。 It's a Github project called Angular Loading Bar . 这是一个名为Angular Loading Bar的Github项目。 Simply bower or npm install and it automatically works on your http requests with Angular. 只需bower或npm install,它就会自动使用Angular处理你的http请求。 Excellent library. 优秀的图书馆

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM