【问题标题】:AngularJS Select - Automatically select optionAngularJS Select - 自动选择选项
【发布时间】:2015-09-25 23:39:40
【问题描述】:

下午,我有一个我在 Angular 中创建的选择框,其中包含一个 FontAwesome 图标而不是文本。你可以在这里看到我不得不使用 ng-bind-html 来让它显示一个 unicode 值,但是现在不起作用的是选择框打开了,它不再'自动选择'当前值。

选择框

<select ng-model="item.IconCssClass" class="fontawesomeselect">
    <option ng-repeat="i in Icons" value="{{i.icon}}" ng-bind-html="i.unicode|html">    </option>
</select>

我的 CSS:

.fontawesomeselect {
    font-family: FontAwesome, Lato;
    width: 40px;
}

在指令中(或多或少):

scope.Icons = [
        { icon: 'fa-phone', unicode: '&#xf095;' },
        { icon: 'fa-gbp', unicode: '&#xf154;' }];

scope.item = { "IconCssClass": "fa-phone" };

选择选项根本不会自动选择,如果我做错了什么有什么想法吗?

【问题讨论】:

  • 您的scope.Icons 数组中似乎不存在fa-lock。尝试在此处添加或将所选图标更改为fa-phonefa-gbp
  • 好吧,我选择了错误的演示项目,现在将更改。该项目肯定存在。

标签: angularjs drop-down-menu font-awesome


【解决方案1】:

您将希望使用ng-selected directive 加载并选择正确的图标。

<option ng-selected="i.icon === item.IconCssClass" ng-repeat="i in Icons" value="{{i.icon}}" ng-bind-html="i.unicode|html"></option>

【讨论】:

  • 我知道这很简单!当我回家时,干杯会尝试:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-02
  • 1970-01-01
  • 2017-08-22
  • 2018-07-15
  • 1970-01-01
相关资源
最近更新 更多