I have a dropdown button. If I select an item from the dropdown list, the main button's action should change to the items action, and the content too.
I tried one version, as you can see above, with controller:
<div class="btn-group">
<button type="button" class="btn" ng-click="mainFunction()">{{buttonCaption}}</button>
<button type="button" class="btn dropdown-toggle">
<span class="caret"></span>
<span class="sr-only">Split button!</span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#" ng-click="update('Action', func1); func1()">Action</a></li>
<li><a href="#" ng-click="update('Another action', func2); func2()">Another action</a></li>
<li><a href="#" ng-click="update('Something else here', func3); func3()">Something else here</a></li>
</ul>
</div>
But it's really ugly, and it would better with directive, for working more than one dropdown button. Somehow the directive should change the main button's ng-click
behavior to the selected item's. Like this:
<!-- button one -->
<div class="btn-group" dropdown>
<button type="button" class="btn btn-danger">{{button1.name}}</button>
<button type="button" class="btn btn-danger dropdown-toggle">
<span class="caret"></span>
<span class="sr-only">Split button!</span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#" ng-click="func1()">do something</a></li>
<li><a href="#" ng-click="func2()">do anything</a></li>
</ul>
</div>
<!-- button two -->
<div class="btn-group" dropdown>
<button type="button" class="btn btn-primary">{{button2.name}}</button>
<button type="button" class="btn btn-primary dropdown-toggle">
<span class="caret"></span>
<span class="sr-only">Split button!</span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#" ng-click="func1()">Action</a></li>
<li><a href="#" ng-click="func2()">Another action</a></li>
<li><a href="#" ng-click="func3()">Something else here</a></li>
</ul>
</div>
Is anybody have a good idea or an example for that?