I have a very big JSON in my controller fetched from a MongoDB database. Here's its structure (haven't added irrelevant keys):
$scope.keyword; //ignore for now explained below
$scope.data = [
{"key" : [
{"nested_key": //some value},
{"nested_key": //some value} //so on
]
},
{"key" : [
{"nested_key": //some value},
{"nested_key": //some value}
]
},
{"key" : [
{"nested_key": //some value},
{"nested_key": //some value}
]
}
]
Here's my HTML template displaying the JSON:
<div ng-repeat="outer in data">
<div ng-repeat="inner in outer.key | keywordFilter: keyword">
//print inner values
</div>
</div>
Here, 'keyword' holds values which will be used to filter the inner ng-repeat loop. Here's my filter:
app.filter('keywordFilter', function() {
return function(collection, keyword) {
//Iteration over the entire collection. If keyword exists add the item to output
return output;
}
})
Now, as expected, the filter runs whenever I modify '$scope.keyword'. It is updated when I click on a button as follows:
HTML:
<input type="text" ng-model="temp" />
<button ng-click="updateKeyword()">
Controller:
$scope.updateKeyword = function() {
$scope.keyword = $scope.temp;
}
The Problem:
Due to the sheer size of data, the filtering process is taking around 10-15 seconds (sometimes the browser hangs!) and THEN the new filtered data returned from the filter is displayed on the screen.
The Requirement:
What I want to do is that during these 10-15 seconds I want to show a loader and after the calculations are done, the news is displayed. How do I achieve this?
What I tried: I figured that once I click on the filter button, I would need to wait for the ng-repeat loop to finish and thus I tried triggering an event on the finish of ng-repeat by referring this thread.
But what I found out is that the event is triggered ONLY when the data is displayed for the first time and not when the filter button is clicked and the data is filtered by the keyword filter.