Search code examples
javascriptangularjsangularjs-scopeangularjs-ng-repeatangularjs-filter

Angularjs clear filter for ng-repeat


I have this ng-repeat condition:

<tr ng-repeat="(k, v) in loanapps | filter:{LoanStatus:SelectedStatus}:true track by $index">
    <td>
        {{v.Id}}
    </td>
    <td>
        {{v.Name}}
    </td>
</tr>

Filtering works fine when I have SelectedStatus value. Now I also want to reset the filter and display all the results.

I have this button click function:

$scope.ResetStatusFilter = function() {
    $scope.SelectedStatus = null;
}

I also tried:

$scope.ResetStatusFilter = function() {
    $scope.SelectedStatus = '';
}

But what this is doing is clearing out all the results.

Is there anyway how can I display all the results and exclude the filter once the button is clicked?

The select list is this one:

<select ng-model="SelectedStatus">
    <option value="Under Review">Under Review</option>
    <option value="Waiting for Meeting">Waiting for Meeting</option>
    <option value="Processing">Processing</option>
</select>

Solution

  • try changing filter:{LoanStatus:SelectedStatus}:true to filter:SelectedStatus.