MyApp.controller(‘SubjectDropDownController’, function ($scope) {
$scope.subjects = [‘Math’, ‘Physics’, ‘Chemistry’, ‘Hindi’, ‘English’];
$scope.selectedItem;
$scope.dropboxitemselected = function (item) {
$scope.selectedItem = item;
alert($scope.selectedItem);
}
});
And the drop down can be modified to bind the selected item as shown in the listing below:
<div ng-controller=”SubjectDropDownController”>
<div class=”dropdown”>
<button class=”btn btn-default dropdown-toggle” type=”button” id=”dropdownMenu1″ data-toggle=”dropdown” aria-haspopup=”true” aria-expanded=”true”>
{{selectedItem}}
<span class=”caret”>span>
button>
<ul class=”dropdown-menu” aria-labelledby=”dropdownMenu1″>
<li ng-repeat=”a in subjects”><a ng-click=”dropboxitemselected(a)”>{{a}}a>li>
ul>
div>
div>