1

So I want to check for multiple values in array of objects with $filter from angular. You can find my code below.

angular.module('app', [])

function ParentCtrl($scope, $filter){
    var list = [{name : "test", value : "test"}, {name: "test1", value: "test"}, { name: 'test', value: 'test1'}];
    var newTemp = $filter("filter")(lst, {name:'test'});
    console.log(newTemp);
}

So what I want is in newTemp to have all objects that have name=test or value=test. With code above I am getting all objects that have name=test. So how can i add one more condition??

I tried also with

var newTemp = $filter("filter")(lst, {name:'test'}) || $filter("filter")(lst, {value:'test'});

but no success.

Micko
  • 431
  • 8
  • 27

2 Answers2

0

Have a look at:

How to filter multiple values (OR operation) in angularJS

There's a couple different ways you can create a custom filter.

Community
  • 1
  • 1
Chewpers
  • 2,430
  • 5
  • 23
  • 30
  • Well i look at that before I write this question. But i try with some solutions and no success.. – Micko Jan 14 '16 at 16:16
0

You can do this:

    var list = [{name : "test", value : "test"}, {name: "test1", value: "test"}, {     name: 'test', value: 'test1'}];
    var newTemp = $filter('filter')(list, function(value, index, array){
        return value.name == "test"; //or any other condition
    });
    console.log(newTemp);
zamarrowski
  • 483
  • 2
  • 7