简体   繁体   中英

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>

尝试将filter:{LoanStatus:SelectedStatus}:true更改为filter:SelectedStatus

Try this short circuiting technique.

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

instead of using filter:{LoanStatus:SelectedStatus}:true to filter:SelectedStatus .

you can clear your filter by using

$scope.SelectedStatus ={}

it will clear the filter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM