Mahajan344 Mahajan344 - 3 months ago 9
AngularJS Question

issue with $filter in angularjs not working with exact search

I am using angularjs

$filter
to filter data based upon
Id
field.
Its searching for partial of
Id
.

Eg. I have array of 3 objects and in all three objects there is
Id
field having values 4105,41,4159 respectively.

Now when I use filter to filter data based upon
Id = 41
. Its returning 1st object which is having value 4105.

I am using filter as below

var filteredData = $filter('filter')($scope.gridUserData.data, { Id: userid });


It should return object with value 41 as that what I filter for?

Answer
 You shoud add which comparator u want exact or any.
 $filter('filter')(array, expression, comparator, anyPropertyKey)
 https://docs.angularjs.org/api/ng/filter/filter
Comments