Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular UI-Bootstrap dropdown button on ng-options

<select class="form-control" data-ng-options="t.name for t in vm.types"
data-ng-model="vm.object.type"></select>

The code above obviously displays a basic dropdown in a standard form-control manner. I've been trying to figure out how to convert this to a button style dropdown using Angular's ui-bootstrap directives but can't seem to get anywhere. Has anyone tried this?

like image 943
zpydee Avatar asked Jan 14 '14 08:01

zpydee


2 Answers

I hope you already found the answer, but maybe someone else will find this useful. The previous answer refers to a common drop down not a button drop down. Here is an example, but without the benefits of hg-option while I didn't use a select but a button.

<div class="input-group">
    <div class="input-group-btn" ng-class='{open: open}'>
        <button class="btn dropdown-toggle"
                data-toggle="dropdown" 
                ng-click='open=!open'>
            Action<span class="caret"></span></button>
                <ul class="dropdown-menu">
                    <li ng-repeat="choice in choices" 
                        ng-click="setChoiceIndex($index);$parent.open =!$parent.open">
                    <a href="#">{{choice}}</a></li>
                </ul>
    </div>
    <input type="text" ng-model="choices[index]" class="form-control">
 </div>

where choices is an array of strings that will be displayed in the drop down and index is another variable in the controller scope that will reflect the selected choice.

like image 159
vladblindu Avatar answered Oct 17 '22 22:10

vladblindu


I have created a basic demo of a drop down using angular bootstrap..

Visit :http://plnkr.co/edit/Mfw5zABqPTgLL4DAgAA3?p=preview

Hope this is what your are looking for.

like image 28
Pranav Avatar answered Oct 17 '22 22:10

Pranav