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

前端 未结 3 1115
暖寄归人
暖寄归人 2021-02-05 03:20

I\'ve written the following proof-of-concept of an Angular app that allows a person to vote for President of the US.




        
3条回答
  •  你的背包
    2021-02-05 03:45

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

提交回复
热议问题