Angularjs过滤按钮点击

时间:2016-03-15 17:26:31

标签: javascript angularjs

我有一个按钮,我将值传递回控制器:

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

它存储在控制器中,如下所示:

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

如果$scope.activeCustomer = detail.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>

任何想法?

由于

1 个答案:

答案 0 :(得分:1)

你与自己拥有的非常接近。

您已在控制器中设置activeCustomer。只需将其传递给过滤器即可。

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