1

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:

enter image description here

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:

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:

enter image description here

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:

enter image description here

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.

At the very least, I'm wondering: how do I make the ui dropdown classes apply directly to the select?

4
  • Where is ui dropdown coming from initially? Commented Mar 29, 2017 at 15:12
  • 2
    can you give us a fiddle / css styles to show us what your problem is. Commented Mar 29, 2017 at 15:15
  • JS fiddle would be more useful. Please provide more information like, if you are using any plugin for select or any other javascript. Thanks Commented Mar 29, 2017 at 15:27
  • I'll try to pare it down so it is in a fiddle. I did realize that it's using a semantic UI dropdown: semantic-ui.com/modules/dropdown.html Commented Mar 29, 2017 at 15:41

2 Answers 2

2

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. 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>
Sign up to request clarification or add additional context in comments.

7 Comments

Is there a way to stop angular styling from being applied to the dropdown? Because this has the same exact effect as what I already tried.
is your drop down custom made or have you used a plugin to achieve the styles&behaviour? I you have used a plugin, please let me know which one you've used
Hi i got this far. plnkr.co/edit/pNiKKDHQEZ6KoZhEuDlO?p=preview . im trying to get the first one to get selected. see if it helps you
the problem is that this uses jquery and angular doesnt go too well with jquery. they're trying to integrate semantic ui with angularjs and its in the testing stages from what i researched.
Thanks for trying but it doesn't work for me. :( I think something else is interfering, but there is so much code involved in this application (which someone else built) that I'm really not sure how to trim it down and put it in a fiddle.
|
1

Hi i got it to work this way. heres a working fiddle. http://plnkr.co/edit/pNiKKDHQEZ6KoZhEuDlO?p=preview

I suppose you might have forgotten to initialise your dropdown.

$(function () {
$('.tag .ui.dropdown').dropdown({allowAdditions: true});  
 });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.