【问题标题】:Angular ng-option filter return all exceptAngular ng-option 过滤器返回除
【发布时间】:2019-09-17 15:23:18
【问题描述】:

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

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',但这仅显示阿尔及利亚,但是,我需要显示所有这些,而不是阿尔及利亚。

【问题讨论】:

  • 纯猜测,试试filter:{ country: '!DZ'}
  • @HastaTamang 不能这样工作:(

标签: javascript angularjs angularjs-directive


【解决方案1】:

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

有关详细信息,请参阅

【讨论】:

    猜你喜欢
    • 2017-12-03
    • 1970-01-01
    • 2014-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-24
    • 2015-09-27
    相关资源
    最近更新 更多