2

I have a filter like so:

<tr ng-repeat="c in CategoryList | filter: {CategoryOption.CategoryOptionID: FilterByType}">

The value: FilterByType gets set from a dropdown list not shown.

This works just fine, except if the FilterByType value is a 2, for example, then it will filter the results to show 2, 22, 32, 42, etc. It's not a true number compare. It's more like a string.contains kinda thing.

Any idea how I can lock this down?

3 Answers 3

3

Add true as a third parameter to the filter expression to enable strict comparison:

<tr ng-repeat="c in CategoryList | filter: {CategoryOption.CategoryOptionID: FilterByType}:true">

Note: This requires AngularJS v1.1.3+

Sign up to request clarification or add additional context in comments.

1 Comment

I tried this method before but continued to get the same weird behavior.
2

You can use a function with filter like this :

<tr ng-repeat="c in CategoryList | filter: myCustomFilter">

And then define a function that does whatever comparison you want :

$scope.myCustomFilter = function(element) {
    if ($scope.FilterByType) {
        return element.number === parseInt($scope.FilterByType);
    }
    return true;
}

This provides total control over the filter and will also help prevent some weird behaviour with input types (text, number, etc.) not matching the actual type in the model.

Comments

0

Adding :true working for me.

ng-repeat="proj in projectList | filter: {ID: project.p_id} :true"

Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.