twitter bootstrap - Collapse navbar on navigate (link click) in mobile mode -


i'm using bootstrap 3 angular. when click link page isn't reloaded, causing menu stay open when in mobile mode.

how make menu close automatically when click menu item?

i have tried adding data-toggle="collapse" data-target=".navbar-responsive-collapse" a tags, causes strange behavior in desktop mode.

this updated version of previous answer

angular.module('app').directive('navcollapse', function () {     return {         restrict: 'a',         link: function (scope, element, attrs) {             var visible = false;              element.on('show.bs.collapse', function () {                 visible = true;             });              element.on("hide.bs.collapse", function () {                 visible = false;             });              element.on('click', function(event) {                 if (visible && 'auto' == element.css('overflow-y')) {                     element.collapse('hide');                 }             });         }     }; }); 

html

    <div class="collapse navbar-collapse navbar-app-collapse" nav-collapse="">         <ul class="nav navbar-nav">          </ul>     </div> 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

visual studio - TFS will not accept changes I've made to a Java project -