首页 > 解决方案 > Angular ng-option 过滤器返回除

问题描述

我有一个来自外部插件的国家/地区列表,这里是一小段摘录:

angular.module('maha.countries').config(['CountriesProvider',
    function(CountriesProvider) {
        CountriesProvider.setCountriesList({
            "AF": "Afghanistan",
            "AX": "Alandinseln",
            "AL": "Albanien",
            "DZ": "Algerien",
            "UM": "Amerikanisch-Ozeanien",
            "AS": "Amerikanisch-Samoa",
        });
    }])
})

我对这些国家有一个选择

<select class="form-control"
        ng-options="country[0] as country[1] for country in countries"
        id="country" name="country">
    <option translate>
        please_choose
    </option>
</select>

现在我想在选择中显示除阿尔及利亚以外的所有国家,例如,我该怎么做?

我尝试使用filter:country='DZ',但这仅显示阿尔及利亚,但是,我需要显示所有这些,而不是阿尔及利亚。

标签: javascriptangularjsangularjs-directive

解决方案


假设country[0]是两个字母的国家代码,使用:

<select class="form-control"
        ng-options="country[0] as country[1] for country in countries 
                     | filter : {'0': '!DZ'} "
        id="country" name="country">
    <option translate>
        please_choose
    </option>
</select>

有关详细信息,请参阅


推荐阅读