dropdown angularjs bootstrap

trying to do dropdown with angularJS and bootsrap by guide, but id doesnt work though 🙂 Here is my code: I dont know, maybe its just old tutorial that i use, but thats all i found by now.

<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <title>Angular</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link rel="stylesheet" href="css/style.css">
    <script src=""></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
    <script src="js/app.js"></script>
</head>
<body ng-controller="dropdown">
<div class="dropdown">
    <button type="button" class="btn btn-danger">Menu</button>
    <button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" ng-model="dd.data.multipleSelect">
    <span class="caret"></span>
    <span class="sr-only">Toggle Dropdown</span>
    </button>
    <ul class="dropdown-menu">
    <li ng-repeat="a in subjects"><a ng-click="dropboxitemselected(a)">{{a}}</a><li>
    </li>
    </ul>
 </div> 
</body>
</html>

var app  = angular.module ('app', []);

app.controller('dropdown', function ($scope) {
    $scope.subjects = ['Math', 'Physics', 'Chemistry', 'Hindi', 'English'];
    $scope.selectedItem;
    $scope.dropboxitemselected = function (item) {

        $scope.selectedItem = item;
        alert($scope.selectedItem);
    };

});

Answer

The bootstrap dropdown example says to wrap everything in a <div class="dropdown">. It doesn’t work if you don’t…

<div class="dropdown">
  <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Dropdown Example
  <span class="caret"></span></button>
  <ul class="dropdown-menu">
    <li><a href="#">HTML</a></li>
    <li><a href="#">CSS</a></li>
    <li><a href="#">JavaScript</a></li>
  </ul>
</div>

Leave a Reply

Your email address will not be published. Required fields are marked *