filter on key/value ng-repeat bug?

3,972 views
Skip to first unread message

ItsLeeOwen

unread,
Apr 11, 2012, 3:02:45 AM4/11/12
to ang...@googlegroups.com
Is this a bug?  The filter is not being executed when ng-repeating the (key,value) in collection.

Misko Hevery

unread,
Apr 11, 2012, 11:27:21 AM4/11/12
to ang...@googlegroups.com
not a bug. Filter works on arrays, and you are trying to filter an object. You need to write your own objectPropertyFilter for that which would iterate over properties and the return an array.

On Wed, Apr 11, 2012 at 12:02 AM, ItsLeeOwen <l...@coderebelbase.com> wrote:
Is this a bug?  The filter is not being executed when ng-repeating the (key,value) in collection.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/bUlU-piCqF0J.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

Peter Bacon Darwin

unread,
Apr 11, 2012, 11:33:18 AM4/11/12
to ang...@googlegroups.com
I.E. This works: http://jsfiddle.net/ZfGx4/3/

Rajendra Auradkar

unread,
Apr 11, 2012, 11:39:09 AM4/11/12
to ang...@googlegroups.com
This for some reason does not work in IE 9....

ItsLeeOwen

unread,
Apr 11, 2012, 11:59:57 AM4/11/12
to ang...@googlegroups.com
Ok, thanks Misko.  What is the recommended approach to writing an objectPropertyFilter to work on an ng-repeat?

Misko Hevery

unread,
Apr 11, 2012, 12:04:42 PM4/11/12
to ang...@googlegroups.com
http://docs-next.angularjs.org/api/angular.module.ng.$filterProvider

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/uZhLyvE5nd8J.

ItsLeeOwen

unread,
Apr 11, 2012, 12:08:33 PM4/11/12
to ang...@googlegroups.com

ItsLeeOwen

unread,
Apr 11, 2012, 12:22:13 PM4/11/12
to ang...@googlegroups.com
Does anyone see what's wrong with this fiddle?

ItsLeeOwen

unread,
Apr 11, 2012, 12:29:35 PM4/11/12
to ang...@googlegroups.com
The filter works outside of an ng-repeat, but not in the ng-repeat.

ItsLeeOwen

unread,
Apr 11, 2012, 12:59:14 PM4/11/12
to ang...@googlegroups.com
Ok, nevermind it does work.  I was expecting the input to be the object, but instead it filters the actual keyword; not the object being repeated.  {{object.value}}  is what is passed to the filter input.

Can you pass multiple arguments to a filter?   | myFilter:[arg1, 'arg2'] ?


ItsLeeOwen

unread,
Apr 11, 2012, 1:34:56 PM4/11/12
to ang...@googlegroups.com
CORRECTION: the custom filter inside of ng-repeat passes the entire associative array as input, not the key/value of each object, or {{ keyword.values }} as I previously misunderstood.

This works:

http://jsfiddle.net/ItsLeeOwen/ZfGx4/


Suller Andras

unread,
Apr 11, 2012, 11:42:26 PM4/11/12
to ang...@googlegroups.com
On Wed, Apr 11, 2012 at 11:59 PM, ItsLeeOwen <l...@coderebelbase.com> wrote:
> Can you pass multiple arguments to a filter?   | myFilter:[arg1, 'arg2'] ?

I think the syntax is | myFilter:arg1:'arg2'

Andras

Benny Lichtner

unread,
Nov 7, 2012, 2:50:27 AM11/7/12
to ang...@googlegroups.com
Is this possible to do without modifying the original object? I don't want my filter to actually destroy my data. I've tried this: http://jsfiddle.net/eNBZW/, but I get a digest iterations error.

Sandip Chitale

unread,
Mar 29, 2013, 2:05:47 AM3/29/13
to ang...@googlegroups.com
Try adding

angular.module('MyApp', []).filter('removeAdam', function() {
    return function(input) {
        input = angular.copy(input);
        $.each( input, function(k,v)
        {
            if( 'Adam' === v.name ) {
                delete input[k];
            }
        });
        return input;
    }
});

It worked for me.
Reply all
Reply to author
Forward
0 new messages