How to filter a select with ng-options in Angular?

filter can only operate on arrays.

But you can create a custom filter:

ElectionApp.filter('females', [ function() {
    return function (object) {
        var array = [];
        angular.forEach(object, function (person) {
            if (person.gender == 'female')
                array.push(person);
        });
        return array;
    };
}]);

and then write

ng-options="name as person.name for (id, person) in ctrl.candidates | females">

Leave a Comment