jquery – 如何在AngularJS中动态分配过滤器

我想过滤以下角色的玩家是html:

 <li role="presentation" ng-repeat="x in availablePlayers | unique:'PlayerRole'" >
    <a href="#pg" aria-controls="pg" role="tab" data-toggle="tab" ng-model="player.PlayerRole">{{x.PlayerRole}}</a>
</li>

这是球员列表

 <tr ng-repeat="x in availablePlayers | filter:player">
            <td data-title="POS">{{x.PlayerRole}}</td>
            <td data-title="Player"><a href="#" class="exclamation">{{x.PlayerName}}</a></td>
            <td data-title="OPP">BOS <span class="white-color">vs</span> Cle</td>
            <td data-title="played">6</td>
            <td data-title="FPPG">42.3</td>
            <td data-title="SALARY"><span class="red-color">${{x.Price}}</span></td>
            <td data-title=""><a href="#"><img src="<?php echo $GLOBALS['RootURL'] ?>images/plus.png" alt="plus"/></a></td>
        </tr>

最佳答案 您可以在filter属性中调用$scope函数.这是我制作的
plunker.

<div ng-app>
  <div ng-controller="MainCtrl">

      <hr>
          <a ng-click="setFilter('John');">Set filter "John"</a>
      <hr>

      <table class="table">
        <tr><th>Name</th><th>Phone</th></tr>
        <tr ng-repeat="friend in friends | filter:getFilter()">
          <td>{{friend.name}}</td>
          <td>{{friend.phone}}</td>
        </tr>
      </table>
  </div>
</div>

你的范围:

function MainCtrl($scope, $http) {
    $scope.friends = [{name:'John', phone:'555-1276'},
                      {name:'Mary', phone:'800-BIG-MARY'},
                      {name:'Mike', phone:'555-4321'},
                      {name:'Adam', phone:'555-5678'},
                      {name:'Julie', phone:'555-8765'}];

    $scope.filter = "";

    $scope.getFilter = function () {
        return $scope.filter;
    };  

    $scope.setFilter = function (filter) {
        $scope.filter = filter;
    };
};
点赞