I wanted to make it work with pure AngularJS and without further JavaScript library, and that turned out to be pretty simple. Only two changes are required, starting with the example here (bootstrap v3):
Instead
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
I used:
<button type="button" class="navbar-toggle" ng-init="isCollapsed = true" ng-click="isCollapsed = !isCollapsed">
and instead
<div class="collapse navbar-collapse">
I used:
<div class="navbar-collapse" ng-class="{collapse: isCollapsed}">
Dropdowns
In addition, if you have drop-down menus in your navigation bar, the same applies to them, except that the css class does not "collapse" but "opens":
<li class="dropdown" ng-class="{ open : dd1 }" ng-init="dd1 = false" ng-click="dd1 = !dd1">
Please note that for a few drop-down lists you will need all the necessary state variable in the angular root area (if you are not using a controller). Therefore, I called the first drop-down menu "dd1" here, it must be unique, otherwise several pop-up menus will open / close at the same time. (which is pretty funny, but rarely used).
yankee May 28 '14 at 17:51 2014-05-28 17:51
source share