r mk r r mk r - 1 year ago 156
AngularJS Question

Filter producing wrong results Angularjs

I have a filter like :

$scope.Approved = $filter('filter')($scope.Summary.CorpEmployees, { locationId: item.Label, evaluationStatusId: '3' });

For some reason the filter is pulling the records whose
evaluationStatusId = 13
Can somebody pls explain why this is happening?
How can I make sure that my filter pulls only those records whose
evaluationStatusId = 3

Answer Source

As per my comment:

You have to use the strict equality parameter called "comparator" in the angularjs docs, otherwise it does a "contains" rather than an "equals" for the filter.

See angular docs for filter here

It would look like this:

$scope.Approved = $filter('filter')(
    { locationId: item.Label, evaluationStatusId: '3' }, 
    true // <--- This is the parameter that forces strict equality
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download