-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(filterFilter): support deeply nested predicate objects #6215
Conversation
Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
@@ -136,6 +136,15 @@ function filterFilter() { | |||
}; | |||
} else { | |||
comparator = function(obj, text) { | |||
if (obj && text && typeof obj === 'object' && typeof text === 'object') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nicer to add these nested checks as predicates to avoid a stack overflow, but this would be a much more complicated fix
@IgorMinar, since you merged 339a165, can you review this? |
I will. |
lgtm |
Due to 339a165, it became impossible to filter nested properties of an object using the filterFilter. A proposed solution to this was to enable the use of nested predicate objects. This change enables the use of these nested predicate objects. Example: ```html <div ng-repeat="it in items | filter:{ address: { country: 'Canuckistan'}}"></div> ``` Or ```js $filter('filter')(items, { address: { country: 'Canuckistan' } }); ``` Closes angular#6215 Related to angular#6009
Thanks, merged |
Due to 339a165, it became impossible to filter nested properties of an object using the filterFilter. A proposed solution to this was to enable the use of nested predicate objects. This change enables the use of these nested predicate objects. Example: ```html <div ng-repeat="it in items | filter:{ address: { country: 'Canuckistan'}}"></div> ``` Or ```js $filter('filter')(items, { address: { country: 'Canuckistan' } }); ``` Closes angular#6215 Related to angular#6009
Thank you! |
Hey @caltp, I'm not sure if this is a real bug or not, but I can't get this to work when using ng-repeat on an object and repeating over its properties. I ended up switching my data over to an indexed array, but ideally it'd be good to support the former as well? Here's a plnkr: http://plnkr.co/edit/mMvAgQgILcBVkbT2q4z4?p=preview |
@3lux I'm not sure what result you're expecting, but what I'm seeing in debugging it is that the items with |
Er, I'm definitely not seeing that result for the ng-repeat walking over the object version. The filter doesn't seem to actually be doing anything for that one. For instance, "1000002" (Pepper White) has a "false" @selected flag, so it shouldn't be outputted. Just in case the link was wrong before: http://plnkr.co/edit/mMvAgQgILcBVkbT2q4z4?p=preview |
Fair enough. It would be good to stick a blurb in the docs somewhere about the inability to use filters when walking over object properties in ng-repeat, since the syntax is the same but technically has different behavior. |
Honestly, it probably should work with Objects, there's no good reason why it can't if we can abstract it nicely, and we already know that filters perform terribly anyways. You should open an issue about supporting object collections so that we can try to implement that, or decide if we can think of a good reason not to. |
Will do, thanks :-) |
…ich prove that _deeply-nested_ predicate objects + _multiple conditions_ was not tested well enough, since some expected scenarios fail. Problem: `filterFilter` is currently behaving like if it was using _OR_ operators (i.e. it doesn't matter if some conditions don't match as long as one does), and should be behaving like if it used _AND_ operators in order to be consistent with the original implementation for non-deeply-nested predicate objects. `filterFilter` working with deeply-nested predicate objects was introduced in 1.2.13 as a result of angular#6215.
…itions not returning expected filtered results Current implementation of `filterFilter` when using deeply nested predicate objects + multiple conditions behaves like if it used _OR_ operators (i.e. it doesn't matter if some conditions don't match as long as one does), and should be behave like if it used _AND_ operators in order to be consistent with the original implementation for non-deeply-nested predicate objects. `filterFilter` working with deeply-nested predicate objects was introduced in 1.2.13 as a result of angular#6215.
…itions not returning expected filtered results Current implementation of `filterFilter` when using deeply nested predicate objects + multiple conditions behaves like if it used _OR_ operators (i.e. it doesn't matter if some conditions don't match as long as one does), and should be behave like if it used _AND_ operators in order to be consistent with the original implementation for non-deeply-nested predicate objects. `filterFilter` working with deeply-nested predicate objects was introduced in 1.2.13 as a result of angular#6215.
Due to 339a165, it became impossible to filter nested properties of an object
using the filterFilter. A proposed solution to this was to enable the use of
nested predicate objects. This fix enables the use of these nested predicate
objects.
Example:
Or
Related to #6009