AngularJS

Angular Directive: Click Elsewhere?

Benefit of this solution:

  1. You only need one bind to $(document). Other firing of events would depend on the $emit of scope events.
  2. You could use both expressions click-elsewhere="show=false", and click-elsewhere="fn()", thanks to $parse.

0

Usage in HTML:

Same with ng-click:

  1. click-elsewhere="fn()"
  2. click-elsewhere="show=false"

A little bit on $parse:

Basically what $parse does is that it converts Angular expression into a function, which could then be called with the scope you want applied to. It’s probably about the entrance to Angular’s magic 🙂

Standard