如何获得有角度的boostrap下拉选择值?

时间:2016-10-26 13:50:11

标签: angularjs twitter-bootstrap drop-down-menu custom-controls

如何从下面的下拉列表中获取所选值。?

<ul class="nav-drop-menu" id="ddlHotelSort">
    <li class="liselect" value="{{ssort.Sort}}" ng-repeat="ssort in vm.searchsort">
    <a href="javascript:void(0)" class="SortClass" name="Sortclass" style="left:0px" value="{{ssort.Sort}}">{{ssort.Name}}
        </a>
    </li>
</ul>

下面是下拉开口的图片.. 如何在角度应用中处理事件和模型值..?

enter image description here

2 个答案:

答案 0 :(得分:1)

<ul class="nav-drop-menu" id="ddlHotelSort">
    <li class="liselect" ng-click="getSelectedItem(ssort);" value="{{ssort.Sort}}" ng-repeat="ssort in vm.searchsort">
    <a href="javascript:void(0)" class="SortClass" name="Sortclass" style="left:0px" value="{{ssort.Sort}}">{{ssort.Name}}
        </a>
    </li>
</ul>

控制器功能

$scope.getSelectedItem = function(item){
  console.log(item);//selected item
}

答案 1 :(得分:1)

只需在li点击中调用一个函数,以下是您的选项示例。

只需点击每个li,

&#13;
&#13;
var app=angular.module('myApp',[])

app.controller('MyCtrl',MyCtrl)

function MyCtrl($scope) {
    $scope.opts = ["Recommended","FirstClass","SecondClass","ThirdClass"            ];
    
    $scope.my_method = function(opt)
    {
    alert(opt)
    }
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<div ng-app ng-controller="MyCtrl">
    <ul>
    <li ng-repeat=" opt in opts" ng-click="my_method(opt)">
        {{ opt }}
    </li>
    </ul>
    
    <p>{{opt}}</p>
</div>
&#13;
&#13;
&#13;

运行代码段并点击每个li

HEre is an example fiddle with your options