[英]Applying multiple CSS classes to an angular select?
I had a normal select in a component's template like this: 我在组件的模板中进行了正常选择,如下所示:
<select id='target-region' multiple="" class="ui dropdown">
<option selected value="01">Europe</option>
<option value="02">North America</option>
<option value="03">South America</option>
<option value="04">Asia</option>
<option value="05">Africa</option>
</select>
This dropdown looks something like this: 这个下拉列表看起来像这样:
I tried to turn it into an angular select like so: 我试着把它变成像这样的角度选择:
<select id="target-region" class="ui dropdown" ng-model="$ctrl.targetRegion" ng-options="item.name for item in $ctrl.TARGET_REGIONS track by item.value" multiple=""></select>
And I placed the following in the JS for the component: 我将以下内容放在组件的JS中:
this.TARGET_REGIONS = [
{ value: '01', name: 'Europe' },
{ value: '02', name: 'North America' },
{ value: '03', name: 'South America' },
{ value: '04', name: 'Asia' },
{ value: '05', name: 'Africa' },
];
this.targetRegion = [this.TARGET_REGIONS[0]];
There are no errors, but the dropdown select is now displaying in an odd way: 没有错误,但下拉选择现在以奇怪的方式显示:
My styling seems to not take effect and clicking on the different options does not select them, so it's not even functional. 我的样式似乎没有生效,单击不同的选项不会选择它们,所以它甚至不起作用。
I inspected the select and saw this: 我检查了选择并看到了这个:
This indicates that the ui dropdown
classes are being applied to an outer wrapper div
created by angular rather than being applied to the select
. 这表示
ui dropdown
类正在应用于由angular创建的外包装div
而不是应用于select
。
At the very least, I'm wondering: how do I make the ui dropdown
classes apply directly to the select? 至少,我想知道:如何让
ui dropdown
类直接应用于选择?
if you're directly trying to convert into angular, you need to change some of the javascript/css in order for ng-options to work. 如果你直接尝试转换为角度,你需要更改一些javascript / css以使ng-options工作。 if you dont want to change anything, i sugggest you try this
如果你不想改变任何东西,我建议你试试这个
<select id='target-region' multiple="" class="ui dropdown">
<option ng-repeat="item in $ctrl.TARGET_REGIONS" value="item.value" >{{item.name}}</option>
</select>
Hi i got it to work this way. 嗨,我让它以这种方式工作。 heres a working fiddle.
这是一个工作小提琴。 http://plnkr.co/edit/pNiKKDHQEZ6KoZhEuDlO?p=preview
http://plnkr.co/edit/pNiKKDHQEZ6KoZhEuDlO?p=preview
I suppose you might have forgotten to initialise your dropdown. 我想你可能忘了初始化你的下拉列表了。
$(function () {
$('.tag .ui.dropdown').dropdown({allowAdditions: true});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.