Angularjs - using orderby filter in the controller's scope
Ok I solved this using $broadcast
and $on
as follows:
$scope.sortList = function(value) { if (value === $scope.currentFilter) { value = value.indexOf('-') === 0 ? value.replace("-","") : "-" + value; } $scope.currentFilter = value; $scope.filtered = $filter('orderBy')($scope.filtered, value); $scope.$broadcast('sorted');}$scope.$on('sorted', function() { $scope.pagedCandidates = getPagedItems($scope, 'filtered');})