1110 1110 - 1 year ago 66
Javascript Question

How to remove angular filter (show all) on specific value?

I have a radio button list and when it is selected I apply filter to list.

My first radio item have value

and I want to remove any filter when that item is selected.

<tr ng-repeat="m in model.list | filter: {GoalId: selectedGoal}" >

So when selectedGoal is -1 I want to show all items (remove filter).

I tried with filter:
{GoalId: selectedGoal && GoalId != -1}
and some other variations but no success.

How can I make this?

Answer Source

It looks like you would be best off writing a filter function.


    <tr ng-repeat="m in model.list | filter: myFilterFn" >

    $scope.myFilterFn = function(m) {
      return (m.goalId === $scope.selectedGoal) || (m.goalId === -1);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download