如何使用ng-options过滤选择

时间:2016-04-21 16:37:21

标签: angularjs angularjs-ng-repeat angularjs-filter ng-options angularjs-ng-options

我正在尝试过滤使用ng-options的选项中的选项但是当我添加过滤器时我根本没有选项

<select id="players"  ng-model="selectedPlayer" ng-options="player.name for player in players track by player.$id | filter:{live:'true'}">
    <option value="">Select player</option>    
</select>

但是过滤器在ng-repeat中运行良好,就像这样

<div ng-repeat="player in players | filter:{live:'true'}">
    {{player.name}}   
</div>

1 个答案:

答案 0 :(得分:3)

你在错误的地方有角filter。过滤器应该应用于players集合,它不应该在最后。

<强>标记

<select id="players" ng-model="selectedPlayer" 
  ng-options="player.name for player in players | filter:{live:'true'} track by player.$id">
    <option value="">Select player</option>    
</select>