Skip to content

Instantly share code, notes, and snippets.

@GuillaumeBiton
Created October 26, 2012 12:48
Show Gist options
  • Save GuillaumeBiton/3958584 to your computer and use it in GitHub Desktop.
Save GuillaumeBiton/3958584 to your computer and use it in GitHub Desktop.
Quick Twitter Bootstrap dropdown with AngularJS

Powering HTML with AngularJS.

Simple Twitter Bootstrap dropdown demo powered by AngularJS.

This method is based on AngularJS attributes. the "dropdown" master DOM is listening "open" variable. if it's true ng-class add the open css class else it's remove. the ng-click event set "open" variable.

demo : http://jsfiddle.net/guillaumebiton/hu78J/1/

<!DOCTYPE html>
<html>
<head>
<meta charset=UTF-8">
<title>AngularJS - Quick Bootstrap dropdown</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
<link rel="stylesheet" type="text/css" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
</head>
<body>
<div class="container ng-scope" ng-app="">
<div class="dropdown clearfix" ng-class="{open: open}">
<a class="btn dropdown-toggle" href="#" ng-click="open=!open">Action<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu">
<li><a tabindex="-1" href="#">Action </a></li>
<li><a tabindex="-1" href="#">Another action</a></li>
<li><a tabindex="-1" href="#">Something else here</a></li>
<li class="divider"></li>
<li><a tabindex="-1" href="#">Separated link</a></li>
</ul>
</div>
</div>
</body>
</html>
@ciastek
Copy link

ciastek commented Jul 10, 2013

Remove href attribute from a.dropdown-toggle to prevent it from navigating to main page. As seen at: http://stackoverflow.com/a/11672909/257443

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment