Finding exact match with filter

2,807 views
Skip to first unread message

Frank Panetta

unread,
Dec 19, 2011, 7:32:55 PM12/19/11
to AngularJS
Hi,

I'm trying to filter an select to only show options that have a
classification of 'User', however this checks if classification
contains 'User' which returns anything that has 'User' in it.

eg-> ng:options="opt.name for opt in references.
$filter({classification:'User'})"


Is there a way to filter for an exact match?

Thanks
Frank

Dan Doyon

unread,
Dec 20, 2011, 12:49:22 AM12/20/11
to ang...@googlegroups.com
Hi,

I created this fiddle which is simplified version from the Array.filter live doc

http://jsfiddle.net/dandoyon/HRzAz/

http://docs-next.angularjs.org/api/angular.Array.filter

--dan

> --
> You received this message because you are subscribed to the Google Groups "AngularJS" group.
> 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.
>

Frank Panetta

unread,
Dec 20, 2011, 12:59:36 AM12/20/11
to AngularJS
Thanks Dan for that, but the filter still shows all values that are
contained in the search filter.

Maybe I'm being unclear. What I mean is that, if I take your example
and change one of the color shades to be 'darker'

function MyCntrl() {
this.colors = [
{name:'black', shade:'dark'},
{name:'whiteblack', shade:'light'},
{name:'red', shade:'darker'},
{name:'blue', shade:'dark'},
{name:'yellow', shade:'light'}
];
}

when I type 'dark' into the search field it shows both 'dark' and
'darker' values. Is there a way to on display data based on an exact
match?

Thanks again.

Frank

> > For more options, visit this group athttp://groups.google.com/group/angular?hl=en.- Hide quoted text -
>
> - Show quoted text -

Dan Doyon

unread,
Dec 20, 2011, 1:32:52 AM12/20/11
to ang...@googlegroups.com
try this again, you are not restricted to search string, i change to a funciton

http://jsfiddle.net/dandoyon/HRzAz/

--dan

Igor Minar

unread,
Dec 20, 2011, 11:13:36 AM12/20/11
to ang...@googlegroups.com
correct. slightly simplified version: http://jsfiddle.net/HRzAz/6/

/i

Frank Panetta

unread,
Dec 21, 2011, 5:35:41 AM12/21/11
to AngularJS
Thanks guys, that's great!

I'm still learning and the more I use angular the more I like it.

Thanks again.
Reply all
Reply to author
Forward
0 new messages