html - 为 ui-select 的每个选项添加不同的 CSS

标签 html css angularjs ui-select

我想为图像中给出的 ui-select 的每个选项添加不同的 CSS,以便每个选项以不同的 text-color

显示

enter image description here

这是带有代码的 Plunk:Plunk

我也试过给出不同的 li 如下所示

<ui-select-choices repeat="item in (itemArray) track by item.id">
   <li style="color:green;">Pending</li>
   <li style="color:red;">Rejected</li>
   <li style="color:blue;">Approved</li>
</ui-select-choices>

但是当我选择该元素时,css 将不会保留。

最佳答案

您可以为数组中的每个元素关联颜色。像这样:

$scope.itemArray = [
    {id: 1, name: 'Pending', color: 'green'},
    {id: 2, name: 'Rejected', color: 'red'},
    {id: 3, name: 'Approved', color: 'blue'},
];

然后,在 ui-select 中,

<ui-select-match>
    <span style="color: {{$select.selected.color}}" ng-bind="$select.selected.name | limitTo: 20"></span>
</ui-select-match>

<ui-select-choices repeat="item in (itemArray) track by item.id">
    <span style="color: {{item.color}}" ng-bind="item.name"></span>
</ui-select-choices>

working plunker

关于html - 为 ui-select 的每个选项添加不同的 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44282878/

相关文章:

javascript - Angular list 模型取消选中也会删除日期

javascript - 仅加载所需的 javascript 和 css

jquery - 响应式移动旋转的问题

javascript - 我想通过加载外部 .js 来更改具有相同类名的元素的样式

javascript - 在 div 中获取一个 carousal table 值

css - Ionic - 使用元素头像类在元素列表中垂直居中文本

javascript - 如何使用 JavaScript 将焦点设置在 HTML 表单中的元素上?

javascript - 将参数传递给javascript中的函数但函数不起作用

javascript - Angular js 验证来自服务器的 JSON

javascript - 使用 ng-model 和 ng-repeat 进行多个默认选择