I would like to capture the event once filtering is completed on my ng-repeat list. I'm filtering through a very large dataset and would like to notify the user that filtering is still happening with a spinning icon. Once filtering is complete, I want to stop the spinning icon. However, I'm having trouble knowing when filtering is in fact complete.
I've tried using a directive on ng-repeat element however this only works on the initial call and doesn't take filtering into account.
I've also tried using $scope.$watch on the filter function, however this also doesn't seem to fire when filtering is complete.
<div>
<input ng-show="showCustNameFilter()"
type="text"
ng-model="criteria.custName"
placeholder="look up customer ...">
<div class="col-md-3" style="margin-top:5px; float:right">
<button type="button" class="btn btn-block btn-primary" ng-click="filter()">
<span ng-show="filtering"><i class="glyphicon glyphicon-refresh spinning"></i></span>
<span ng-show="!filtering"><i class="fa fa-filter"></i></span> Filter
</button>
</div>
</div>
<ul>
<li ng-repeat="i in ts.items | filter : customerNameFilter">
<p>{{i.site.custCode}}</p>
</li>
</ul>
JavaScript
$scope.filterCustName = undefined;
$scope.filtering = false;
$scope.filter = function () {
$scope.filtering = true;
if ($scope.criteria.custName !== undefined) {
$scope.filterCustName = $scope.criteria.custName;
$scope.filterCustCode = undefined;
}
$scope.filtering = false; //this has no affect...
};
$scope.customerNameFilter = function (item) {
if ($scope.filterCustName !== undefined)
return item !== undefined ?
item.site.custName.indexOf($scope.filterCustName) > -1 : true;
else
return true;
};
Thanks in advance!