himanshu
himanshu

Reputation: 208

Is it possible to filter with multiple condition in angularjs?

I have an array of objects named result.data.EAPP_USERS

0:Object

SECURITYCLASS:90

USERID:"ASISH90"

1:Object

SECURITYCLASS:90

USERID:"VANDERSONIR"

2:Object

SECURITYCLASS:90

USERID:"BISWA90"

3:Object

SECURITYCLASS:93

USERID:"TABITHA93"


4:Object

SECURITYCLASS:93

USERID:"ASISH93"

5:Object

SECURITYCLASS:95

USERID:"TAB95"


6:Object

SECURITYCLASS:95

USERID:"ASISH95"

I want to filter data with SECURITYCLASS value 90 and 93. I have tries this code

$scope.OpportunityOwners = $filter('filter')(result.data.EAPP_USERS, { SECURITYCLASS: "90"} || {SECURITYCLASS: "93"});

but the result contains object with SECURITYCLASS value 90 only. i.e

0: Object
SECURITYCLASS: 90
USERID: "ASISH90" 

1: Object
SECURITYCLASS: 90
USERID: "VANDERSONIR"

2: Object
SECURITYCLASS: 90
USERID: "BISWA90"

I know its possible to filter by SECURITYCLASS: "90" and SECURITYCLASS: "93" ; merge them to get the final result.

but Is it possible by using $filter only once?

Is it possible to filter with multiple constraints ?

Upvotes: 1

Views: 9544

Answers (1)

daan.desmedt
daan.desmedt

Reputation: 3820

You should create a custom filter. By evaluating multiple conditions in one filter it will gain 'performance'.

$scope.filterData = function (item) {
    return (item.SECURITYCLASS === 90 || item.SECURITYCLASS === 93);
}

On your view :

<div ng-repeat="item in data | filter:filterData">
    {{::item}}
</div>

See Plunkr

Upvotes: 3

Related Questions