angular-filter
angular-filter copied to clipboard
"First" filter fails with expressions
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
Can you please provide some jsbin/fiddle example, @thisischrisj ?
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
Thanks @thisischrisj, It's been changed after this discussion: https://github.com/a8m/angular-filter/issues/19#issuecomment-55025048 Thoughts?
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.
Awesome @thisischrisj, thanks! Feel free to PR.
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.