Search code examples
angularjsangular-filters

Angular filter exact match


Okay so i wasnt quite sure what to call this question.

But i have the following ng-repeat:

ng-repeat="module in modules |filter:{ module_type_id: selectedItem.id } |filter:search:strict"

This is iterating through objects that looks like this:

{id: 1, name: 'Hello', module_type_id: 5}

Now i have 12 module types so any of these objects have a module_type_id between 1 and 12.

When i click one of the categories thereby selecting a type the variable selectedItem is set to that value. (which then sorts the list)

This works however there is an odd bug.

if i choose the category that has id 1 then elements with id 1, 10, 11,12

my guess is that the filter is taking part of the value and therefor only shows results that contains the value. and since 1,10,11,12 all contain the value 1 then these results are shown.

So how can i make sure that it only shows the result that exactly match the value?


Solution

  • Filter takes another parameter that makes it strict, you're using it for your second part...

    ng-repeat="module in modules |filter:{ module_type_id: selectedItem.id } : true |filter:search:strict"