-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Null filter not returning anything: filter:{category:null}" #1780
Comments
Substituting null with '!' works for me: <span ng-repeat="obj in objs | filter:{category:'!'}">{{obj.name}}<br/></span> |
Thanks that helps. It's a hack though so i still think this needs to be fixed. |
Unfortunately, this is not working for values mapped from select which use ng-options and one default value (which has to be value=""). |
As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months. Please try the newest versions of Angular ( Thanks! |
This is still present in 1.2.0, is there any solution available when using ng-options besides writing a custom filter function? |
I found that the only way to solve this problem is to manually write the
See this fiddle: http://jsfiddle.net/wiebl/jjC4H/ |
+1. bug still presented in 1.2.0 |
Another way to allow a null value in a filter object is to use this as a comparator:
|
+1 Bug still present in 1.2.1 & 1.2.6 |
+1 still present in 1.2.8 Please reopen! |
|
Still present |
Thanks to everyone for pointing this out as something to address! Looks like many people have said this is still present, reopening. |
I also experienced this issue today with a |
I'm also having this problem with a |
I will get on it tomorrow On Tue, 18 Nov 2014 9:19 pm Georgios Kalpakas notifications@github.com
|
This does not appear to be a valid issue anymore - here is a test using Angular 1.3.3: http://plnkr.co/edit/PqBVbewbf8ogv2h6z1CZ?p=preview |
I've been trying to tell them for over a month now (#1780 (comment)). @wesleycho: How did you do it so quickly ? 😸 |
@gkalpak sorry about that. we need a better way to escalate comments from people like you. I believe @petebacondarwin has reached out to you already. We are going to fix this communication issue. |
@IgorMinar: |
Strange, I thought I was sure I saw it! I created a plunker with a null value and it seemed to work fine though: http://plnkr.co/edit/0HDbP7?p=preview Sorry to raise concern! Cheers @wesleycho |
I am using Angular v1.3.0-rc.1 and am getting the issue. I was able to get around it using the "undefined" keyword.
|
@shellybelle v1.3.0-rc.1 is like reallly old and RC version... If you see any unwanted behaviour you should test with the latest stable release and open a separate issue if you believe that there is still some kind of a bug in the latest version. |
this works for me:
|
Please reopen this! This problem still exists in Angular 1.4.3 making it unusable for working with an empty option in combination with |
@rjd22, it seems to be working as expected in 1.4.3+ as well. |
@gkalpak after updating to angular 1.4.5 the problem seems to be solved. |
@rjd22, that's great ! |
I am also seeing this behaviour, see this http://plnkr.co/edit/92POTX?p=preview I at least expect the filter to be cleared when selecting the empty option, but instead it seems to be filtering on role === null. Am I doing it wrong, or is this indeed a bug/issue that should be fixed? |
I think it is so by design. So, while there are workarounds, it seems that out-of-the-box Not sure how this could be fixed without breaking stuff. /cc @petebacondarwin |
Simple workaround inside the filter expression: http://plnkr.co/edit/QiueNR?p=preview Here is a better solution along the lines of what @gkalpak suggests. You can provide a directive that returns the result of an expression for the empty value (http://plnkr.co/edit/hMYGNR?p=preview): <select ng-model="filter.role" ng-options="role for role in roles" ng-empty-value="undefined">
<option value="">Select role in band</option>
</select> The code looks like: app.directive('ngEmptyValue', ['$parse', function($parse) {
return {
require: ['select', 'ngModel'],
link: function(scope, element, attrs, controllers) {
var select = controllers[0];
var readValue = select.readValue;
var emptyValue = $parse(attrs.ngEmptyValue)(scope);
select.readValue = function() {
if (element.val() == '')return emptyValue;
return readValue();
};
}
};
}]); The question is whether we need to add this to the core... |
@petebacondarwin your solution solves my issue, so for me this is solved. But it might be a good idea to either add to the core, or give an example in the docs perhaps? |
Let's add it as an additional attribute to the |
@wilguevara this worked for me too! Thanks
|
As explained in this thread here and #13471 (comment), the workarounds are simple and robust enough that it's not necessary to have this functionality in core. Here's another way to create an empty value directive that doesn't rely on private API: http://plnkr.co/edit/S9XHqf?p=preview This could be easily released as a small 3rd party module if needed. |
Dataset:
When i create an ng-repeat like this it returns the expected subset:
ng-repeat="obj in objs | filter:{category:1}"
But when i do this it does not show anything: (search for null instead of 1)
ng-repeat="obj in objs | filter:{category:null}"
This behaviour has been tested in 1.1.1 and 1.0.1 on chrome 23.0.1271.97 and IE9.
Plnkr and jsfiddle demo's:
http://plnkr.co/edit/jgfPPE
http://jsfiddle.net/KQYMY/17/
The text was updated successfully, but these errors were encountered: