Reputation: 1295
I have an Angular Bootstrap dropdown menu that doesn't seem to be toggling the dropdown. On click, nothing shows up, although I can see the list items on inspect element.
HTML:
<div ng-controller="DropdownCtrl">
<!-- Simple dropdown -->
<span class="dropdown" dropdown on-toggle="toggled(open)">
<a href class="dropdown-toggle {{ disableDropdown }}" dropdown-toggle>
<i class="fa fa-align-justify"></i>
</a>
<ul class="dropdown-menu port-dropdown-menu">
<li>test</li>
<li>test2</li>
<li ng-repeat="choice in dropdown.items">
<a ui-sref="portfolio.port({portId: choice.id})">{{ choice.title }}</a>
</li>
</ul>
</span>
</div>
DropdownCtrl:
'use strict';
angular.module('portfolioManager').controller('DropdownCtrl', function ($scope, portfolioCreateService) {
$scope.dropdown = {};
$scope.dropdown.items = portfolioCreateService.getDropdownTabs();
$scope.disableDropdown = portfolioCreateService.getDropdownClass();
$scope.$on('dropdownStatus', function(){
$scope.disableDropdown = portfolioCreateService.getDropdownClass();
console.log($scope.dropdown.items);
});
$scope.status = {
isopen: false
};
$scope.toggled = function(open) {
$log.log('Dropdown is now: ', open);
};
$scope.toggleDropdown = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.status.isopen = !$scope.status.isopen;
};
});
Upvotes: 2
Views: 7190
Reputation: 1
I have also faced problems with Original Bootstrap dropdown (also have imported the Angularjs UI Bootstrap), but it's something like: Only 2 clicks trigger the dropdown-menu, when I use it in an navbar just like the demo in Bootstrap's Offical Page. For example:
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
<li class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
Only after I remove the data-toggle="dropdown"
, will the Original Bootstrap dropdown functioning well in an Navbar...Maybe it's because data-toggle="dropdown"
will also let Angularjs UI Bootstrap binds dropdown-toggle directives.
Upvotes: 0
Reputation: 7351
I you're using lower version of angular than 1.3.0, then the <a href class="dropdown-toggle {{ disableDropdown }}" dropdown-toggle>
binds two dropdown-toggle directives. Then when you click the element the first directive opens the dropdown and then the second one closes it immediately.
Delete the attribute dropdown-toggle
from the element and it should work.
Upvotes: 1