Angular js conditional filtering?

I am trying to disable the filter when I select the "all" option for my selected ng model.

Here's the code:

Search: <input ng-model="searchText">
Search By: 
<select ng-model="queryBy">
    <option value="$">all</option>
    <option value="1">category 1</option>
    <option value="2">category 2</option>
    <option value="3">category 3</option>
</select>
<ul>
    <li ng-repeat="message in messages | filter:searchText | filter: {category: queryBy}"></li>
</ul>

      

When I select the first option ("$"), I want the filter to be disabled. Is there a way to do this? Thank!

+3


source to share


1 answer


I just figured it out myself. I just needed to change "$" to "", an empty string. Since the empty string does not define the filter criteria, the filter is not applied. Thus, the revised code:

<select ng-model="queryBy">
<option value="">all</option>
<option value="1">category 1</option>
<option value="2">category 2</option>
<option value="3">category 3</option>

      



+1


source







All Articles