Neil
Neil

Reputation: 107

How to filter a Select with ng-options

I'm trying to filter the options in a select that uses ng-options but when I add the filter I get no options at all

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

But the filter works fine in an ng-repeat like this

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

Upvotes: 1

Views: 9550

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136144

You had angular filter on wrong place. Filter should be applied over a players collection, it should not be at the end.

Markup

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

Upvotes: 4

Related Questions