简体   繁体   English

单击按钮时 Angularjs 过滤器

[英]Angularjs filter on button click

I have a button where I am passing the value back to the controller:我有一个按钮,我将值传递回控制器:

<button type="button" ng-model="activeCustomer" value="active" ng-click="getVal($event)" ng-class="{'active':activeCustomer === 'active'}" class="btn btn-default">Active</button>

Its being stored in the controller like this:它像这样存储在控制器中:

$scope.activeCustomer='active';
$scope.getVal=function(active){
        $scope.activeCustomer=active.currentTarget.value;
    }

I want to filter my list by $scope.activeCustomer if detail.activeCustomer = $scope.activeCustomer如果detail.activeCustomer = $scope.activeCustomer我想按$scope.activeCustomer过滤我的列表

<tr ng-repeat="detail in theRecords | orderBy:sortType:sortReverse | filter:searchCustomer" ng-click="expandCustomer(detail.theCustId)" class="drillable">
    <td>{{ detail.fullname }}</td>
    <td>{{ detail.email }}</td>
    <td>{{ detail.phone }}</td>
    <td>
      <p ng-bind="{{ detail.firstcontact }} | date:'dd/MM/yy'"></p>
    </td>
    <td>{{ detail.theMainAddress }}</td>
    <td>{{ detail.paymentType  }}</td>
    <td>{{ detail.theStatus }}</td>
    <td>{{ detail.activeCustomer }}</td>
  </tr>

any ideas?有任何想法吗?

Thanks谢谢

You're very close with what you have.你非常接近你所拥有的。

You're already setting the activeCustomer in your controller.您已经在控制器中设置了 activeCustomer。 Just pass that to the filter.只需将其传递给过滤器即可。

<tr ng-repeat="detail in theRecords | 
    orderBy:sortType:sortReverse | filter:activeCustomer">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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