首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >修改ng-options

修改ng-options
EN

Stack Overflow用户
提问于 2016-02-22 17:11:33
回答 2查看 86关注 0票数 0

我的json对象是:-

代码语言:javascript
复制
{    "callingCodes": [
        {
            "name": "United States",
            "code": "+1",
            "isoCode": "US",
            "isFree":"true",
            "flag":"flag us" 
        },
        {
            "name": "Turkey",
            "code": "+90",
            "isoCode": "TR",
            "isFree":"true",
        "flag":"flag tr" 
        }]

我正在使用国家代码精灵图像来显示国家旗帜。我使用ng-repeat来显示特定的标志。

代码语言:javascript
复制
<td><span style="display: inline-block; margin-left: auto;" ng-class="{{'countryData.flag'}}"></span></td>

它工作得很好。现在,我想使用相同的css类在ng-options (下拉列表)中包含该标志。

代码语言:javascript
复制
<select id="countryCode" class="form-control" ng-required="true" ng-model='sendMsgData.toCountryCode' 
       ng-options="supportedCode.code as (supportedCode.code + '(' + supportedCode.isoCode + ')') for supportedCode in supportedCountryCallingCodes">
                 <option value="">Country Code</option>
              </select>

我如何才能做到这一点。

EN

回答 2

Stack Overflow用户

发布于 2016-02-22 17:22:08

option标签上使用ng-repeat

代码语言:javascript
复制
<select id="countryCode" class="form-control" ng-required="true" ng-model="sendMsgData.toCountryCode">
    <option ng-repeat="supportedCode in supportedCountryCallingCodes" value="supportedCode.code" ng-class="countryData.flag">{{supportedCode.code}}</option>
</select>
票数 0
EN

Stack Overflow用户

发布于 2016-02-22 17:23:57

添加选项-类

代码语言:javascript
复制
  <select id="countryCode" class="form-control" ng-required="true" ng-model='sendMsgData.toCountryCode'   options-class="countryData.flag"
   ng-options="supportedCode.code as (supportedCode.code + '(' + supportedCode.isoCode + ')') for supportedCode in supportedCountryCallingCodes">
             <option value="">Country Code</option>
          </select>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35549648

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档