Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

feat(filterFilter): support deeply nested predicate objects #6215

Closed
wants to merge 1 commit into from

Conversation

caitp
Copy link
Contributor

@caitp caitp commented Feb 11, 2014

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:

<div ng-repeat="it in items | filter:{ address: { country: 'Canuckistan'}}"></div>

Or

$filter('filter')(items, { address: { country: 'Canuckistan' } });

Related to #6009

@mary-poppins
Copy link

Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.

  • Uses the issue template (#6215)

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

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') {
Copy link
Contributor Author

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

@caitp caitp added this to the 1.2.13 milestone Feb 11, 2014
@caitp
Copy link
Contributor Author

caitp commented Feb 11, 2014

@IgorMinar, since you merged 339a165, can you review this?

@IgorMinar
Copy link
Contributor

I will.

@IgorMinar
Copy link
Contributor

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
@caitp caitp closed this in b4eed8a Feb 11, 2014
@caitp
Copy link
Contributor Author

caitp commented Feb 11, 2014

Thanks, merged

@IgorMinar IgorMinar mentioned this pull request Feb 13, 2014
khepin pushed a commit to khepin/angular.js that referenced this pull request Feb 19, 2014
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
@shql shql mentioned this pull request Feb 20, 2014
@shql
Copy link

shql commented Feb 20, 2014

Thank you!

@quantizor
Copy link

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

@caitp
Copy link
Contributor Author

caitp commented Feb 28, 2014

@3lux I'm not sure what result you're expecting, but what I'm seeing in debugging it is that the items with flags: { @selected: "true" } are matching, and the ones with flags: { @selected: "false" } aren't. Is that not what you're expecting?

@quantizor
Copy link

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

@caitp
Copy link
Contributor Author

caitp commented Feb 28, 2014

@3lux so yeah, the filterFilter supports nested object predicates, but the collection itself has to be an array / array-like seen here

That's why you're seeing that issue.

@quantizor
Copy link

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.

@caitp
Copy link
Contributor Author

caitp commented Feb 28, 2014

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.

@quantizor
Copy link

Will do, thanks :-)

albertboada added a commit to albertboada/angular.js that referenced this pull request May 2, 2014
…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.
albertboada added a commit to albertboada/angular.js that referenced this pull request Jul 5, 2014
…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.
albertboada added a commit to albertboada/angular.js that referenced this pull request Jul 6, 2014
…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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants