noor
noor

Reputation: 681

ionic filter by more than one condition

I want to filter through multiple statuses.

I have the following JSON

[{name:'firstPerson',status:1},{name:'secondPerson',status:2},{name:'thirdPerson',status:3}]

And I loop through them

<div class="card" data-ng-repeat="res in result | filter:{ status:0, status:2} as avilableNames" >
    <div class="item item-text-wrap">
        <div class="row">
            <div class="col">
                <li>{{res.name}}</li>
            </div> 
        </div>
    </div>
</div>
<ul>
    <li  ng-if="avilableNames.length===0">
        There are no available names for that status
    </li>
</ul>

I have tried:

$scope.myFilter = function (item) 
{
return item = 0 || item = 2 ; 
};

Upvotes: 0

Views: 742

Answers (1)

Lotus91
Lotus91

Reputation: 1125

You can use a filter function like this; notice the .status:

$scope.myFilter = function(item){
return item.status == 0 || item.status == 2;
};

And in your ng-repeat use it like this :

<div ng-repeat="res in results | filter:myFilter">{{res.name}}</div>

Upvotes: 3

Related Questions