user6440175 user6440175 - 5 months ago 27
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');


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.