Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
46
rated 0 times [  49] [ 3]  / answers: 1 / hits: 5352  / 11 Years ago, thu, december 12, 2013, 12:00:00

I need to filter the rows in witch the property age is greater than x number



    <a href=# ng-click=personFilter = {age:18}>Older than 18</a>

<div ng-repeat=person in persons | filter:personFilter >
<div>{{person.name}}</div>
<div>{{person.age}}</div>
</div>


Thanks in advance


More From » angularjs

 Answers
2

According to the docs, you can pass a function to filter: Here's an example.



<!DOCTYPE html>
<html>

<head>
<script [email protected] data-semver=1.2.4 src=http://code.angularjs.org/1.2.4/angular.js></script>
<link rel=stylesheet href=style.css />
<script src=script.js></script>
</head>

<body ng-app=example ng-controller=Ex>
<!-- on click set the filter to our custom function defined in scope -->
<a href=# ng-click=personFilter = isOver18>Older than 18</a>
<ul>
<li ng-repeat=p in people | filter:personFilter>
{{p.name}} - {{p.age}}
</li>
</ul>
</body>

</html>


controller:



angular.module('example', [])
.controller('Ex', function($scope) {
$scope.personFilter = {};
$scope.people = [
{name: Bob, age: 32},
{name: 'Billy', age: 12}
];

/* returns true if the provided person is over 18 */
$scope.isOver18 = function(p) {
return p.age > 18;
}
});

[#49590] Thursday, December 12, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckinleyk

Total Points: 730
Total Questions: 99
Total Answers: 99

Location: South Georgia
Member since Fri, Nov 13, 2020
4 Years ago
;