Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The latest (unstable) versions of Angular introduce a hook for you to drop in a comparator function, which is where I'd LIKE to put what I'm about to show you. But, I'm stuck on v1.0.7, so I had to approach it with the below.</p> <p>The issue is that even though the user selects an empty string when they select the "empty" option, the property on the object you're filtering against still exists, so Angular's $filter compares each elements' matching property to that empty string, instead of treating that property as removed.</p> <p>So, I added an <code>ng-change</code> event on my <code>&lt;select /&gt;</code> directive which would <em>delete</em> the property from my filter template object, thereby resetting the filter. Been working for me so far!</p> <p>Example:</p> <pre><code>&lt;!-- Assuming select1 is the filter template object, note the ng-change attribute added to your select element --&gt; &lt;select ng-change="checkForClear( select1 )" ng-model="select1.name" ng-options="item.name as item.name for item in items" &gt; &lt;option value=""&gt;No filter&lt;/option&gt; &lt;/select&gt; &lt;div ng-repeat="item in items | filter:select1"&gt; {{ item.name }}: {{ item.fruit }} &lt;/div&gt; &lt;!-- Then, in your controller --&gt; &lt;script&gt; // Assuming your controller is set up... $scope.checkForClear = function( filterTemplate ){ if( filterTemplate.name == null || filterTemplate.name === '' ){ delete filterTemplate.name; // &lt;== THIS removes the property from the template filter and clears the filter for Angular } } &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload