user6440175 user6440175 - 1 year ago 83
AngularJS Question

Angular filter doesnt return the expected result

I am trying to filter this json by the first name. I am expecting the result to be A1, but I am doing something wrong.

$filter('filter')('[{ "ID": 1, "FirstName": "A1", "L1": "Sabrina" }, { "ID": 2, "FirstName": "A2", "LastName": "L2" }]', 'A1');

Answer Source

I don't think you can use $filter with pure JSON.

var arr = JSON.parse('[{ "ID": 1, "FirstName": "A1", "L1": "Sabrina" }, { "ID": 2, "FirstName": "A2", "LastName": "L2" }]');
var a1  = $filter('filter')(arr, 'A1');

Returns the expected result.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download