Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular js conditional filtering?

Tags:

angularjs

I'm trying to disable the filter when I select the "all" option for my select 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? Thanks!

like image 362
user3587412 Avatar asked Aug 13 '26 01:08

user3587412


1 Answers

I just figured it out myself. I just had to change the "$" to "", an empty string. Since an empty string doesn't specify a filter criteria, a filter isn't applied. So the revised code would be:

<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>

like image 140
user3587412 Avatar answered Aug 16 '26 11:08

user3587412