1

If I have something like :

{{(myList|filter:{state:"INFO"}).length}}

I am basically filtering on a specific Object property in my list. How do I do it in Javascript.

Currently the JavaScript takes only the value not the Object property.

$filter("filter")(myList,"INFO")

This works but isn't right as it looks for INFO in all object properties for single record.

$filter("filter")(myList,"INFO")

This is what I need but doesn't work as entire string is being used for filtering not treating as Object Property : Value pair

Any ideas around this ?

1
  • 3
    Have you tried $filter("filter")(myList,{state:"INFO"})? Commented Apr 28, 2014 at 14:51

2 Answers 2

1

You could do:

$filter('filter')(myList,function(item){
   return (item.state == 'INFO')
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, this works perfect for my requirement
0

An example of filtering Array of Objects based on key:value object property using Angular $filter in JavaScript | not in HTML template

var data= $filter('filter')(myList, {state: 'INFO'});

// view data
if (console) console.log(data);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.