leonel
leonel

Reputation: 10214

AngularJS: how to filter by two expressions with $filter

Here's the $fiter documentation: https://docs.angularjs.org/api/ng/filter/filter

I accomplish what I need with the following:

$scope.images = $filter('filter')(imageList, { type: 'snapshot' });
$scope.images = $filter('filter')($scope.images, { status: 'ACTIVE' });

But I would like to refactor and simplify the code, preferably using one line of code instead of two.

I have looked around and some people suggest using a custom filter. Is there a way to accomplish it by using $filter out of the box?

Thanks in advance!

Upvotes: 0

Views: 67

Answers (1)

Carlos Man
Carlos Man

Reputation: 368

I think you can combine both in one line like this:

$scope.images = $filter('filter')(imageList, { type: 'snapshot', status: 'ACTIVE' });

Upvotes: 1

Related Questions