Recognize when angular bootstrap dropdown-menu is closed

orikoko picture orikoko · Dec 11, 2014 · Viewed 9.2k times · Source

Is there a way to recognize that angular-bootstrap dropdown-menu is closed? I want to recognize this event and run specific function.

<div class="btn-group" dropdown is-open="status.isopen">
  <button type="button" class="btn btn-primary dropdown-toggle" dropdown-toggle ng-disabled="disabled">
    Button dropdown <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" role="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>
  </ul>
</div> 

Answer

Ben Diamant picture Ben Diamant · Dec 11, 2014

Add to your parent div an on-toggle event

<div class="btn-group" dropdown is-open="status.isopen" on-toggle="toggled(open)">

And handle it witin the controller

$scope.toggled = function(open) {
    if (open) {
        console.log('is open');
    } else console.log('close');
}