Filtering list items two different ways using ng:eval...

594 views
Skip to first unread message

pkre...@gmail.com

unread,
Dec 4, 2011, 11:51:55 PM12/4/11
to ang...@googlegroups.com
I have a list of objects with the properties 'title' and 'favorite'. I'd like to display a filtered list and can filter by 'title' using $filter in 0.9.19.

But I'd like to filter the list _either_ by title _or_ by favorite without creating a copy of the HTML for each version. Here's an example: http://jsfiddle.net/vZfeY/2/

- the fiddle includes 5 different tries at getting it to work, I've just disabled cases by changing the 'ng' namespace on those I'm not testing.

- because I want to filter depending on two different HTML input items, I had to use an 'ng:eval' to build the right search expression

- but when I try to call a function in the ng:eval expression, I get no filtering at all

- and if I try to call a function inside the 'ng:repeat ... $filter(expression)' for expression, I also get no filtering

1) I'm sure there's a better way, I just haven't found it
2) even if I don't use it in the end for this, am I using ng:eval incorrectly? Shouldn't I be able to call a function from it?

Thanks,
Per

Hekke

unread,
Dec 5, 2011, 3:36:48 AM12/5/11
to AngularJS
I've updated you fiddle:

http://jsfiddle.net/vZfeY/3/

The reason that you couldn't call a function inside $filter, was that
your function wasn't declared on the scope - notice that I assign it
to the scope name 'filter'.

/Hekke

pkre...@gmail.com

unread,
Dec 5, 2011, 9:13:36 AM12/5/11
to ang...@googlegroups.com
Hekke,

You might be on to something but in the fiddle you sent, it doesn't seem to work any better and I actually can't see where you attach the function to a new scope named 'filter'. Would you mind commenting where you made a change? Does it work when you test it?

Thanks in advance,
Per

Igor Minar

unread,
Dec 5, 2011, 11:20:40 AM12/5/11
to ang...@googlegroups.com
I think that this is what you want: http://jsfiddle.net/IgorMinar/vZfeY/4/

/i

Per

--
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/-/-Lih2nnwFVsJ.

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.

Hekke

unread,
Dec 5, 2011, 2:44:59 PM12/5/11
to AngularJS
Wow, sorry.

I Don't know what went wrong? I had it working as described, but the
fiddle I linked to was clearly wrong.

Good thing Igor knows how to tame jsfiddle :)

/Hekke

pkre...@gmail.com

unread,
Dec 5, 2011, 10:43:00 PM12/5/11
to ang...@googlegroups.com
Yes, that's it exactly. Thank you.

I'm not clear on what made it work. Was it adding the function to the 'this' scope? I only wrote it without based on other Fiddles.

Will try in my own code.

Regards,
Per

pkre...@gmail.com

unread,
Dec 5, 2011, 10:43:38 PM12/5/11
to ang...@googlegroups.com
Thanks for the effort anyway, help always appreciated.

Per
Reply all
Reply to author
Forward
0 new messages