user2404324
user2404324

Reputation: 11

Angular JS Filtering in javascript controllers

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 ?

Upvotes: 1

Views: 89

Answers (2)

Syed Ekram Uddin
Syed Ekram Uddin

Reputation: 3101

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);

Upvotes: 0

btm1
btm1

Reputation: 3856

You could do:

$filter('filter')(myList,function(item){
   return (item.state == 'INFO')
});

Upvotes: 1

Related Questions