2

I have an Angular service that goes away to retrieve a pretty big JSON file (nearly 10,000 lines).

The problem i am facing, is that it is taking some time to bind the data to the front-end (as expected).

Sample controller:

$scope.dataLoaded = false;

serviceReport.getData( function (data) {
    $scope.data1 = data.data1;
    $scope.data2 = data.data2;
    $scope.data3 = data.data3;
    $scope.data4 = data.data4;
    $scope.data5 = data.data5;
    $scope.data6 = data.data6;
    $scope.data7 = data.data7;
    $scope.data8 = data.data8;
    $scope.data9 = data.data9;
    $scope.data10 = data.data10;
    $scope.data11 = data.data11;
    $scope.data12 = data.data12;
    $scope.data13 = data.data13;
    $scope.data14 = data.data14;
    $scope.data15 = data.data15;
    $scope.data16 = data.data16;
    $scope.data17 = data.data17;

    $scope.dataLoaded = true;
});

Service:

app.factory('serviceReport', function($http) {
    return {
        getData: function(value,done) {
            $http.get('data.json', {
                })
            .success(function(data) { 
                done(data);
            })
            .error(function(error) {
                alert('An error occured');
            });
        }
    }
});

I have ng-cloak on my HTML element, when dataLoaded = true, this is removed as it indicates the data is available to be displayed.

How can i improve the service call/data bind? Would splitting the call help?

5
  • 1
    Why don't yu show a loader while it's loading the data ? Commented Sep 9, 2014 at 13:55
  • @ExpertSystem - i currently am showing a loader.. I guess what i am asking is, can i display data1,2,3,4 ASAP as they are at the top of the page and then load the rest? Commented Sep 9, 2014 at 14:04
  • You can, but the delay is probably due to fetching the data, so other than splitting up the request, there doesn't seem to be much more you can do. Commented Sep 9, 2014 at 14:06
  • I am thinking of a server-side fix, and a client-side fix, you are trying to fix this entirely on browser-side?, or a solution involving the server is acceptable too ? Commented Sep 9, 2014 at 15:51
  • @dseminara - browser-side for the time being. Commented Sep 10, 2014 at 12:46

1 Answer 1

1

Server-side solution would be to reduce the size of the response and make more requests with smaller responses. Do you actually need the whole response at start? You have to be aware that binding the whole response will generate many watchers, which will slow down all subsequent digests.

Client-side solution would be to bind the response part by part in a loop as a callback parameter for $scope.$apply() or even $timeout().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.