Provides a directive to specifiy a behaviour when click/tap events happen outside an element. This can be easily used to implement eg. close on outer click feature for a dropdown.

Usage

Declare it as a dependency to your app unless you have already included some of its super-modules.

angular.module('myApp', ['mobile-angular-ui']);

Or

angular.module('myApp', ['mobile-angular-ui.core']);

Or

angular.module('myApp', ['mobile-angular-ui.core.outerClick']);

Use ui-outer-click to define an expression to evaluate when an Outer Click event happens. Use ui-outer-click-if parameter to define a condition to enable/disable the listener.

<div class="btn-group">
  <a ui-turn-on='myDropdown' class='btn'>
    <i class="fa fa-ellipsis-v"></i>
  </a>
  <ul
    class="dropdown-menu"
    ui-outer-click="Ui.turnOff('myDropdown')"
    ui-outer-click-if="Ui.active('myDropdown')"
    role="menu"
    ui-show="myDropdown"
    ui-shared-state="myDropdown"
    ui-turn-off="myDropdown">

    <li><a>Action</a></li>
    <li><a>Another action</a></li>
    <li><a>Something else here</a></li>
    <li class="divider"></li>
    <li><a>Separated link</a></li>
  </ul>
</div>

    This is a service function that binds a callback to be conditionally executed when a click event happens outside a specified element.

    Ie.

    app.directive('myDirective', function('bindOuterClick'){
      return {
        link: function(scope, element) {
          bindOuterClick(element, function(scope, extra){
            alert('You clicked ouside me!');
          }, function(e){
            return element.hasClass('disabled') ? true : false;
          });
        }
      };
    });
    
    ParamTypeDescription
    elementDomElement | $element

    The element to bind to.

    callbackfunction

    A function(scope, options), usually the result of $parse, that is called when an outer click event happens.

    conditionstring | function

    Angular $watch expression to decide whether to run callback or not.

      Evaluates an expression when an Outer Click event happens.

      ParamTypeDescription
      uiOuterClickexpression

      Expression to evaluate when an Outer Click event happens.

      uiOuterClickIfexpression

      Condition to enable/disable the listener. Defaults to true.


      comments powered by Disqus