如何将dropdown
菜单中的所选项目添加到打开dropdown
的按钮?
示例:我想将“DIFFERENCES”替换为从下拉菜单中选择的文本;如果我选择“全部”,则文本“差异”应替换为“全部”......
<div class="filter-requests btn-group">
<div data-toggle="dropdown">
<a href="#" class="btn btn-default dropdown-toggle">
DIFFERENCES
<i class="fa fa-chevron-down"></i>
</a>
</div>
<ul class="dropdown-menu">
<li><a href="#">All</a></li>
<li><a href="#" >Exclusions</a></li>
<li><a href="#" >Differences</a></li>
<li><a href="#" >Variable Differences</a></li>
<li><a href="#" >Path Differences</a></li>
</ul>
</div>
答案 0 :(得分:1)
尝试这样。
var app = angular.module("app",[]);
app.controller("ctrl" , function($scope){
$scope.row = "";
$scope.items = ['All','Exclusions','Differences','Variable Differences'];
$scope.selectRow = function(item){
$scope.row = item;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl" class="filter-requests btn-group">
<div data-toggle="dropdown">
<a href="#" class="btn btn-default dropdown-toggle">
{{row}}
<i class="fa fa-chevron-down"></i>
</a>
</div>
<ul class="dropdown-menu" >
<li ng-repeat="item in items" ng-click="selectRow(item)">
<a href="">{{item}}</a>
</li>
</ul>
</div>
答案 1 :(得分:1)
<强> view.html 强>
config('searchService.myConsumerKey');
<强> controller.js 强>
<div class="btn-group" uib-dropdown is-open="status.isopen">
<button id="single-button" type="button" class="btn btn-primary" uib-dropdown-toggle>
{{selected || 'Select one'}} <span class="caret"></span>
</button>
<ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="single-button">
<li role="menuitem"><a href="#" ng-click="changeOption('Action')">Action</a></li>
<li role="menuitem"><a href="#" ng-click="changeOption('Another action')">Another action</a></li>
<li role="menuitem"><a href="#" ng-click="changeOption('Something else here')">Something else here</a></li>
<li class="divider"></li>
<li role="menuitem"><a href="#" ng-click="changeOption('Separated link')">Separated link</a></li>
</ul>
</div>