I have a project where I'm fetching data from a database and having to iterate through the returned object tree to manipulate the data, and as these manipulations are time consuming (lots of data), it's impacting the page loading times.
The original - unprocessed data is useful as is, so I'd like to set the $scope.data object with the unprocessed data, and then replace it once the processing is complete.
I was thinking something like this:
dataFactory.getAssets()
.success(function(data) {
$scope.assets = data; /* sets data in view */
}
})
.then(function(data) {
dataFactory.processAssets(data); /* post-processes data*/
$scope.assets = data; /* sets processed data in view */
})
.error(function(data) {
$log.log(data.error + ' ' + status);
});
I'm obviously missing something here, and any help would be appreciated.
Basically I want to do this:
- getData from Database
- set $scope.view = data to display raw data on page
- send data to be processed in the background while page is being viewed
- reset $scope.view to = processed data when processing is finished