1

I need to do an exact match filter, but having some trouble getting it to work.

I have set up a jsfiddle for this issue that works fine, until I add in the ":true" on this line.

  <li ng-repeat="worktime in worktimes  = (worktimes | filter:{ employeeId : employeeFilter }:true)">{{worktime.customerName}}</li>

It then doesn't work anymore. What am I doing wrong?

In my app I have an issue that I hope has the same cause.

Positonic
  • 9,151
  • 14
  • 57
  • 84

2 Answers2

1

Your HTML renders like below on View

<select ng-model="employeeFilter" style="width: 100px;" class="ng-pristine ng-valid">
    <option value="? string: ?"></option>
    <option value="7" class="ng-scope ng-binding">Jamie</option>
    <option value="37" class="ng-scope ng-binding">Anne</option>
    <option value="8" class="ng-scope ng-binding">James</option>
</select>

In which value of employeeFilter means the option value of select box which are present in "" like value="7" for Jamie.

You are mentioning true in your filter, that means you're making strongly type check.

In this case 7==="7" is not true. Therefore you need to parse the variable to integer before filtering, after parsing "7" will become 7 you will get expected result like 7===7 //will become true

HTML

<select ng-model="employeeFilter" style="width: 100px;">
           <option data-ng-repeat="employee in employeesFilterList" value="{{employee.id}}">{{employee.username}}</option>
      </select>

Controller

$scope.doParseInt = function(val){
    if(val && val != "")
    return parseInt(val)
} 

Working Fiddle

This could be helpful to you. Thanks.

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
0
<li ng-repeat="worktime in worktimes | filter: {'employeeId': employeeFilter} : true ">{{worktime.customerName}}</li>

this will work

simon
  • 1,415
  • 10
  • 20