如何使用 ng-options 过滤 Select

How to filter a Select with ng-options

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

<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>

你 angular 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>