Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  140] [ 1]  / answers: 1 / hits: 18585  / 11 Years ago, wed, july 31, 2013, 12:00:00

I'm applying a greater than filter to a ng-repeat tag. I wrote the following custom filter function:



$scope.priceRangeFilter = function (location) {
return location.price >= $scope.minPrice;
};


and I use it in the following HTML code:



<div ng-repeat=m in map.markers | filter:priceRangeFilter>


What is the best way to trigger a refresh of the ng-repeat tag when $scope.minPrice is updated?


More From » angularjs

 Answers
40

It should be automatic. When $scope.minPrice is changed, the repeater will be automatically updated.



function Ctrl($scope,  $timeout) {
$scope.map = [{
name: 'map1',
price: 1
}, {
name: 'map2',
price: 2
}, {
name: 'map3',
price: 3
}];
$scope.minPrice = 0;
$scope.priceRangeFilter = function (location) {
return location.price >= $scope.minPrice;
};

$timeout(function () {
$scope.minPrice = 1.5;
}, 2000);
}


Demo on jsFiddle


[#76625] Tuesday, July 30, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gideons

Total Points: 197
Total Questions: 106
Total Answers: 108

Location: Moldova
Member since Sat, Jan 29, 2022
2 Years ago
gideons questions
Tue, Nov 9, 21, 00:00, 3 Years ago
Sat, Jan 2, 21, 00:00, 3 Years ago
Wed, Oct 28, 20, 00:00, 4 Years ago
Thu, May 21, 20, 00:00, 4 Years ago
;