When ui-select is inside a modal popup, items do not show up properly
I'm experiencing the same problem as described here: http://stackoverflow.com/questions/29893423/angular-ui-select-is-not-displaying-the-list-of-options-when-included-in-angular The second answer to that issue appears to be correct. For some reason, the $select.items.length is 0, causing the dropdown list to be ng-hidden, even though the items are there (and can be seen if you inspect the DOM). Only solution appears to be hacking the template, as is suggested in the above SO post.
I just ran into this while trying to use ngDialog. I noticed the ng-hide on the select options too, so I hacked it and added ng-hide="!$select.open" to my select-choices effectively overriding the logic within which allowed me to get it working without messing with the template. Hope this helps others :)
I got this to work by altering the template in a hacky way. You can see below that I switched from using ng-show to a bound expression in the style attribute.
style="display:{{$select.items.length && $select.open ? \'block\':\'none\'}}"
Earlier, I had tried ng-hide, ng-show, and ng-class, and none of them worked. I wonder if this has to do with some kind of ng-animate behavior?
Full copy/paste available below: (adjust the theme prefix as necessary)
.run(function ($templateCache) {
$templateCache.put('bootstrap/choices.tpl.html',
'<ul class="ui-select-choices ui-select-choices-content dropdown-menu" role="listbox" style="display:{{$select.items.length && $select.open ? \'block\':\'none\'}}" >' +
'<li class="ui-select-choices-group" id="ui-select-choices-{{ $select.generatedId }}">' +
'<div class="divider" ng-show="$select.isGrouped && $index > 0"></div>' +
'<div ng-show="$select.isGrouped" class="ui-select-choices-group-label dropdown-header" ng-bind="$group.name"></div>' +
'<div id="ui-select-choices-row-{{ $select.generatedId }}-{{$index}}" class="ui-select-choices-row" ' +
'ng-class="{active: $select.isActive(this), disabled: $select.isDisabled(this)}" role="option">' +
'<a href="javascript:void(0)" class="ui-select-choices-row-inner"></a>' +
'</div>' +
'</li>' +
'</ul>');
});
Error occurs here in select.js
(line 610: ctrl.searchInput.css('width', '10px');)
In this case input tag has width: 10px. You can click in this 10px-area - and it will work. As we use this lib via bower - I've fix it without touching source in the following way:
<ui-select-match placeholder="placeholder..." ng-class="{empty: !account.roles.length}">{{::$item.name}}</ui-select-match>
so, if model array is empty - just make width of input 100%. We use 'select2' theme
.empty.ui-select-match + .select2-search-field,
.empty.ui-select-match + .select2-search-field input{
width: 100% !important;
}
@DeezCashews thanks a lot. It works well in my case.
@curios no problem, if you want to upvote my answer on the SO link mentioned it will help others find faster
I've experienced this issue when I've nested my ui-select inside an ng-show initially set to be false when the page is first rendered. I've tracked it down to the ctrl.sizeSearchInput function inside the uiSelectCtrl controller, the search input is set to 10px wide and this doesn't change after the ng-show section is visible.
I've followed the advice of @captify-ddavydov for now and implemented styles that don't include the .empty class name (as my situation isn't about an empty list - my list is populated at the point the problem happens).
.ui-select-match + .select2-search-field,
.ui-select-match + .select2-search-field input{
width: 100% !important;
}
Scrap the above, that breaks the rendering - it causes the control to render two lines when an option is selected:

Try using ng-if instead of ng-show. It solved for me.
Using ng-if instead of ng-show also solved it for me.
Experienced this same issue when ui-select was in a collapsing panel hidden with ng-class. I ended up using the same fix as @captify-ddavydov and @andrewmurray. I can live with the doubled height that @andrewmurray mentions.
For anyone using the Boostrap theme, this is all it took for me:
ui-select-match + .ui-select-search,
.ui-select-match + .ui-select-search input{
width: 100% !important;
}
Closing this as a usage issue.
@prakhar-goel Where does the ng-if go?
I'm bitten by this issue. Tried many of the solutions and none work. The issue happens inside an ng-show which is exposing the select list when a button is clicked. If I move the select outside of the show it works. Boo.
@tkserver
I also met this problem while using ui-modal and I solve this using 'ng-class' condition to the ui-select-choices directive:
modal.html
<ui-select ng-model="person.selected" theme="bootstrap" on-select="onSelect($item)" ng-click="select_open = true">
<ui-select-match placeholder="制作者">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="item in people | propsFilter: {name: $select.search, email: $select.search}" ng-class="{ 'select_open': select_open }">
<div ng-bind-html="item.name | highlight: $select.search"></div>
<small ng-bind-html="item.email | highlight: $select.search"></small>
</ui-select-choices>
<ui-select-no-choice>
一致するものは見つかりませんでした。
</ui-select-no-choice>
</ui-select>
app.js
$scope.onSelect = function(item) {
$scope.open_select = false;
}
style.css
.select_open {
opacity: 1 !important;
}
Hope it helps. 👍
Thanks for the tip! I'm trying to remember what I was doing and what project I was on so I can use it!