Spearfisher
Spearfisher

Reputation: 8783

ng-repeat: how to add multiple filters?

I'd like to use multiple filters on the same item for an ng-repeat. The idea is that for each job below I have different properties like location and salary and I'd like to be able to filter the results with both criteria.

So far, I've tried this:

<div ng-repeat="job in jobs | filter: location | filter: salary">

But it's obviously not working.

Does anyone have a clue how to fix this?

Thanks

Upvotes: 3

Views: 353

Answers (2)

R3tep
R3tep

Reputation: 12864

You can create a custom filter.

<div ng-repeat="job in jobs | filter:customFilter">

And in your controller :

 $scope.customFilter = function(item) {
   if('Condition on your item')
     return true;
   return false;

 }

Upvotes: 2

Mikke
Mikke

Reputation: 2167

You can use parenthesis to nest expressions:

<div ng-repeat="(job in job | filter:location) | filter:salary">

Upvotes: 2

Related Questions