Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"First" filter fails with expressions #78

Open
thisischrisj opened this issue Jan 18, 2015 · 6 comments
Open

"First" filter fails with expressions #78

thisischrisj opened this issue Jan 18, 2015 · 6 comments

Comments

@thisischrisj
Copy link

Given this data:

$scope.types = [
    {
        "name": "type1",
        "default": false
    },
    {
       "name": "type2",
       "default": true
    }
];

This failed:
<div type="{{ (types | first: 'default === true').name }}"></div>

I had to revert to:
<div type="{{ ((types | where: {default:true}) | first).name }}"></div>

As a test I also did:
<div type="{{ (types | first: 1).name }}"></div>
but didn't seem to work either

This was working on 0.4.5 but not in 0.5.2

@a8m
Copy link
Owner

a8m commented Jan 18, 2015

Can you please provide some jsbin/fiddle example, @thisischrisj ?

@thisischrisj
Copy link
Author

Here you go

0.4.4: http://jsfiddle.net/jg1k73xm/1/
0.5.2: http://jsfiddle.net/jg1k73xm/2/

I know I mentioned v0.4.5 but I couldn't link to the src. I checked with 0.4.6 but got the same result as 0.5.2

@a8m
Copy link
Owner

a8m commented Jan 18, 2015

Thanks @thisischrisj,
It's been changed after this discussion: #19 (comment)
Thoughts?

@thisischrisj
Copy link
Author

I can see the logic and my second example shows that reasonable workarounds exist. I would just recommend updating the documentation as this still references the ability to use expressions with first, last, etc...

It probably wouldn't hurt to mention your decision on "only filter without an arguments return an object" too. This would help users understand expected return types.

@a8m
Copy link
Owner

a8m commented Jan 18, 2015

Awesome @thisischrisj, thanks!
Feel free to PR.

@HugCoder
Copy link

While 'first' seems to be fixed, the same problem seems to apply to 'last' when it's an array of objects not a simple array. Using version 0.5.17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants