3

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!

2
  • Just figured it out myself. I just had to change the "$" to "" Commented Dec 13, 2014 at 16:52
  • 1
    Then put it as an answer to this question, SO explicitly encourage users to answer their own questions. Commented Dec 13, 2014 at 16:54

1 Answer 1

1

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.