In this plunker我想要選擇下拉列表的列表。問題是下拉列表顯示爲空(默認情況下,沒有選擇標籤,如控制器中設置的那樣)。如何解決這個問題?在Angular UI下拉列表中設置初始標籤
的Javascript
var app = angular.module('app', ['ui.bootstrap']);
app.controller('ctl', function ($scope) {
$scope.rows = [ {selection: "Sel 1"}, {selection: "Sel 2"} ];
$scope.selectItem = function(ev,index) {
var sel = ev.target.textContent;
$scope.lastSelection = index + " - " + sel;
$scope.rows[index].selection = sel;
};
});
HTML
<table>
<tr ng-repeat="row in rows">
<td>
<div class="btn-group" uib-dropdown>
<button id="btn-append-to-body" type="button" class="btn btn-primary" uib-dropdown-toggle="">
{{selection}} <span class="caret"></span>
</button>
<ul class="dropdown-menu" ng-click="selectItem($event,$index)" uib-dropdown-menu="" role="menu" aria-labelledby="btn-append-to-body">
<li role="menuitem">
<a href="#" data-value="1" >The first item</a>
</li>
<li role="menuitem">
<a href="#" data-value="2">Another item</a>
</li>
<li role="menuitem">
<a href="#" data-value="3">Yet another item</a>
</li>
</ul>
</div>
</td>
</tr>
</table>
<br/>
Last selection: {{lastSelection}}
感謝,我固定的,但我仍然有@ ps0604更新我的答案,寫正確的語法問題 – ps0604
搶劫,請檢查。 – oguzhan00