AngularJS http获得settimeout逻辑

我有一个问题,公司之一有这么多的数据,加载这么长的时间,以显示在我的AngularJs项目。 有时,当连接种类被切断或请求超时时,它不会出现。 那时,我的客户要显示一些消息,并重新运行该函数来重新加载数据。 后端正在使用NodeJS。

请帮助我如何充分满足我客户的要求。

这是我的代码从后端获取数据。

$scope.tableParams = new ngTableParams({ page: 1, // show first page count: 20, // count per page sorting: { title: 'asc' // initial sorting }, filter: { title: filterText, is_active: $scope.IsActive } }, { total: 0, getData: function ($defer, params) { companyService.getDataBelongToCompany($scope.companyId, params.url()).then(function (data) { params.total(data.total); $defer.resolve(data.jobs); $scope.collapsed = false; }, function () { $defer.resolve([]); }); } }); 

我认为你需要的是使用服务器端的分页。 如果响应时间太长,则应限制后端发送的数据并对其进行分页,因为这会影响用户体验。

在这里你可以find更多关于如何与ngTable分页的信息:

ngTable分页文档

一种方法是在http请求中添加超时如下

$http.get('url', {timeout: 5000}); 如果超过5秒,可以在.error()函数中显示消息

检查这个答案的更多细节如何在AngularJs中设置全局http超时