AngularJS Select - 自动选择选项

时间:2015-09-25 15:04:16

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

下午所有,我有一个我在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" };

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

1 个答案:

答案 0 :(得分: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>