Search code examples
angularjsfilterangularjs-filter

Angularjs filter on two values of one field


I need to use either a filter or another, how to do?

<tr ng-repeat="currentCollectionItem in binding 
               | filter: ({ isPending: false } || {isPending: undefined})">

Solution

  • Solution

    You can do this using only one condition:

    filter:'!true'
    

    This is how you can apply false and undefined properties.

    Example

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Example - example-filter-filter-production</title>
      <script src="//code.angularjs.org/snapshot/angular.min.js"></script>
    </head>
    <body ng-app="">
    <div ng-init="binding = [{name:'John', isPending:false},
                             {name:'Mary', isPending:false},
                             {name:'Mike', isPending:undefined},
                             {name:'Adam'},
                             {name:'Julie', isPending:true},
                             {name:'Juliette', isPending:true}]"></div>
    
    <table id="searchTextResults">
      <tr><th>Name</th><th>isPending</th></tr>
      <tr ng-repeat="currentCollectionItem in binding | filter:'!true'">
        <td>{{ currentCollectionItem.name }}</td>
        <td ng-show="{{currentCollectionItem.isPending !== undefined}}">{{ currentCollectionItem.isPending }}</td>
        <td ng-show="{{currentCollectionItem.isPending === undefined}}">undefined</td>
      </tr>
    </table>
    </body>
    </html>