Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent an angular-bootstrap dropdown from closing (Unbind Event which was bound by a directive)

I am using the Angular-Bootstrap Dropdown. I want to prevent it from closing on click until the user closes it intentionally.

Default state is: The Dropdown closes when clicking somewhere in the Document.

I identified the relevant lines of code: (Line 12, dropdown.js)

this.open = function( dropdownScope ) {    if ( !openScope ) {      $document.bind('click', closeDropdown); // line to unbind      $document.bind('keydown', escapeKeyBind);    } } 

You can find the full code here: Link to Github

I don't want to change the original sources of angular-bootstrap to keep my project open for updates.

My question:

How can i unbind an event bound by a Directive to the document in an Angular Controller?

like image 481
ulilicht Avatar asked May 16 '14 14:05

ulilicht


People also ask

How do I make bootstrap dropdown stay open?

Just wrap the contents of the menu in a form tag. That's it. So, instead of ul. dropdown-menu , use form.


1 Answers

I solved this by adding the following to my drop down-menu. This prevents the drop down from closing unless you click on the tag that opens it

<ul class="dropdown-menu" ng-click="$event.stopPropagation()"> 
like image 114
Dane Avatar answered Oct 08 '22 16:10

Dane