1

I have one issue that one of companies has so many data that make to load so long to be displayed in my AngularJs project. Sometimes, it does not appear when kind of connection is cut off or request time out. At that time, what my client is to show some message and re-run that function again to reload data. Backend is using NodeJS.

Please help me how to full-fill my client's request.

Here is my code to get data from backend.

$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([]);
        });
    }
});
PPShein
  • 13,309
  • 42
  • 142
  • 227

2 Answers2

1

I think that what you need is to use a server-side pagination. If the response takes so long you should limit the data sent by your backend and paginate it because it will affect the user experience.

Here you can find more information about how to paginate with ngTable:

ngTable pagination documentation

miquelarranz
  • 876
  • 11
  • 26
0

one method is to add timeout in http request as below

$http.get('url', {timeout: 5000}); if it takes more than 5 secs you can show message in .error() function

Check this answer for more details How to set a global http timeout in AngularJs

Community
  • 1
  • 1
rashidnk
  • 4,096
  • 2
  • 22
  • 32