Angular UI-Bootstrap dropdown button on ng-options
Asked Answered
U

2

7
<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?

Untwist answered 14/1, 2014 at 8:12 Comment(0)
J
9

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.

Jennajenne answered 29/7, 2014 at 9:25 Comment(1)
I am looking for a click-outside close directive also, but all I found yet is very complicated. If anybody has a clue, I think it could be a great add-on to this answer.Jennajenne
S
6

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.

Stockjobber answered 14/1, 2014 at 9:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.