Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have an angular filter by input text. for the given list

initialViewModel.users = [
{user: 'Nithin',phone: 'Azus', price: 13000}, 
{user: 'Saritha',phone: 'MotoG1',price: 12000}, 
{user: 'Renjith',phone: 'MotoG2',price: 14000}, 
{user: 'Felix',phone: 'Nexus',price: 21000}];

It is returning incorrect results for the filter texts a,g,m,n,o,s,u,z.

Sample fiddle here.

        <ul>
            <li ng-repeat="user in Model.users | filter: Model.name | orderBy:'price'">{{user.user + ' bought phone worth ' + user.price}}</li>
        </ul>

Say for example, if I filter it with 'a' it should return only the one record having name saritha. Instead it returns two records.

share|improve this question
up vote 2 down vote accepted

By default angular filters by any property of an object. If you want to filter by specific property you need to update your filter:

<li ng-repeat="user in Model.users | filter: { user: Model.name } | orderBy:'price'">
    {{user.user + ' bought phone worth ' + user.price}}
</li>

Pay attention to this part: filter: { user: Model.name }. In this case you are telling angular to filter only property user of your object.

Here is an updated JSFiddle

share|improve this answer
    
yeah. That's it. Thanks a bunch. – Praveen Prasannan Sep 8 '15 at 5:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.